Skip to content

Commit 1ebfc8d

Browse files
committed
修复挑战 02 bug
1 parent df2cd8b commit 1ebfc8d

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.DS_Store
1+
.*
2+
.*/
3+
24
venv/
35
__pycache__/
46
*.pyc

02-income-tax-calculator-enhancement/challenge2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def main():
5050
income = int(income_string)
5151
except ValueError:
5252
print('Parameter Error')
53+
continue
5354
_, remain = calc_income_tax_and_remain(income)
5455
print('{}:{}'.format(employee_id, remain))
5556

03-income-tax-calculator-use-config-file/challenge3.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
]
2727

2828
# 命令行参数处理类
29+
30+
2931
class Args(object):
3032

3133
# 初始化的时候读取命令行中输入的所有参数到 self.args 列表
@@ -59,11 +61,14 @@ def userdata_path(self):
5961
def export_path(self):
6062
return self._value_after_option('-o')
6163

64+
6265
# 创建命令行参数处理的对象 args
6366
# 在此处创建的原因是后续的 class Config 的代码定义中需要用到这个对象
6467
args = Args()
6568

6669
# 配置文件读取处理类
70+
71+
6772
class Config(object):
6873

6974
# 初始化的时候调用内部接口 self._read_config() 读取配置文件中的所有内容
@@ -124,12 +129,15 @@ def social_insurance_total_rate(self):
124129
self._get_config('GongJiJin')
125130
])
126131

132+
127133
# 创建配置文件处理的对象 config
128134
# 在此处创建的原因是后续的 class IncomeTaxCalculator
129135
# 的代码定义中需要用到这个对象
130136
config = Config()
131137

132138
# 用户工资文件处理类
139+
140+
133141
class UserData(object):
134142

135143
# 初始化过程,读取用户工资文件并将数据存入到 userdata 列表中
@@ -166,6 +174,8 @@ def __iter__(self):
166174
return iter(self.userdata)
167175

168176
# 税后工资计算类
177+
178+
169179
class IncomeTaxCalculator(object):
170180

171181
# 初始化的时候传入 UserData 对象,传进来后赋值给 self.userdata
@@ -218,7 +228,8 @@ def calc_for_all_userdata(self):
218228
# 初始化返回的数据结果,包含工号和税前工资
219229
data = [employee_id, income]
220230
# 计算需要缴纳的社保,注意需要保留两位小数
221-
social_insurance_money = '{:.2f}'.format(self.calc_social_insurance_money(income))
231+
social_insurance_money = '{:.2f}'.format(
232+
self.calc_social_insurance_money(income))
222233
# 计算个税及税后工资,注意需要保留两位小数
223234
tax, remain = self.calc_income_tax_and_remain(income)
224235
# 将社保、个税及税后工资补充到返回的数据列表中
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[DEFAULT]
2+
JiShuL = 2193.00
3+
JiShuH = 16446.00
4+
YangLao = 0.08
5+
YiLiao = 0.02
6+
ShiYe = 0.005
7+
GongShang = 0
8+
ShengYu = 0
9+
GongJiJin = 0.06
10+
11+
[CHENGDU]
12+
JiShuL = 2193.00
13+
JiShuH = 16446.00
14+
YangLao = 0.08
15+
YiLiao = 0.02
16+
ShiYe = 0.005
17+
GongShang = 0
18+
ShengYu = 0
19+
GongJiJin = 0.06
20+
21+
[BEIJING]
22+
JiShuL = 4251.00
23+
JiShuH = 21258.00
24+
YangLao = 0.08
25+
YiLiao = 0.02
26+
ShiYe = 0.002
27+
GongShang = 0
28+
ShengYu = 0
29+
GongJiJin = 0.12
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
101,3500
2+
203,5000
3+
309,15000

0 commit comments

Comments
 (0)