学习编程,运用if elif else 语句 while 语句 来实现循环个人税收计算
税收明示表
工资范围85000及以上是45%
工资范围60001=85000是35%
工资范围40001=60000是30%
工资范围30001-40000是25%
工资范围17001-30000是20%
工资范围8001-17000是10%
工资范围5001-8000是3%
5000不收税
答案
def 选择():
print('1.个人工资税收查询\n2.退出')
user=input('请输入选择')
print('2.退出')
return user
def 税收():
x = 0
print('税收明示表\n工资范围85000及以上是45%\n工资范围60001=85000是35%\n工资范围40001=60000是30%\n工资范围30001-40000是25%\n工资范围17001-30000是20%\n工资范围8001-17000是10%\n工资范围5001-8000是3%\n5000不收税')
while True:
user = float(input('你的工资是多少'))
if user > 85000:
x = user * 0.45
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
elif user >= 60001:
x = user * 0.35
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
elif user >= 40001:
x = user * 0.30
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
elif user >= 30001:
x = user * 0.25
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
elif user >= 17001:
x = user * 0.20
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
elif user >= 8001:
x = user * 0.10
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
elif user >= 5001:
x = user * 0.03
y = user - x
print(f'你应该交{x}', f'你的工资是{y}')
break
else:
print('你不需要交税')
break
while True:
user=选择()
if user == '1':
税收()
elif user == '':
print('无法生效')
elif user == '2':
print('拜拜')
break
结果图: