python代码测试健康指数计算器_python编写的bmi体重指数计
算器、出租车费⽤计算。。。
'''
写四个函数 分别包含bmi体重指数计算器、出租车费⽤计算器、个税计算器、猜数字游戏
'''
#体重指数计算器
def bmi():
while 1:
#声明变量 ⾝⾼、体重
height=input('请输⼊您的体重(m):')
weight=input('请输⼊您的体重(kg):')
#如果输⼊的⾝⾼或者体重有⼀个为0,直接结束循环
#or 或的关系 关键字,多个条件时,只要有⼀个条件成⽴即可执⾏代码块
#将输⼊的⾝⾼ 体重 转换为⼩数float类型
if height=='0'or weight=='0':
print('您输⼊的数据有误,程序已结束!')
break
#and 与的关系 关键字 多个条件时,条件必须同时成⽴才⾏
if height=='1.8'and weight=='70':
print('扫⼀扫吧')
#not 表⽰⾮得关系
height=float(height)
weight=float(weight)
bmi=weight/(height*height)
print(bmi)
if bmi<18.5:
print('体重过轻...')
elif 18.5<=bmi<=23.9:
print('标准⾝材')
elif 24<=bmi<=27:
print('过重!')
elif 28<=bmi<=32:
print('⼤胖⼦')
else:
print('超级⽆敌⼤胖⼦')
def tax():
while 1:
# 快速多⾏缩进,可以选中需要缩进的⾏,按Tab键
# 1.输⼊⼀个公⾥数
kilo = input('请输⼊⼀个公⾥数(km,输⼊0结束):')
# 2.将公⾥数转换为float类型
kilo = float(kilo)
# 如果kilo的值为0,结束循环
if kilo == 0:
print('欢迎下次使⽤!Bye bye!')
break
# 3.根据不同的公⾥数计算需要的车费
elif kilo <= 2:
代码转换print('起步价,8元')
elif kilo <= 12:
price = 8 + (kilo - 2) * 1.2
# 占位符 %f 专门⽤来给float类型的数据做占位的
# %.2f,保留⼩数点后两位
print('共⾏驶%.2f千⽶,共%.2f元' % (kilo, price)) else:
price = 20 + (kilo - 12) * 1.5
print('共⾏驶%.2f千⽶,共%.2f元' % (kilo, price))
def calc():
while 1:
# 输⼊⼯资
salary = input('请输⼊您的税前⼯资(元),输⼊0结束:') # 将⼯资转换为float类型
salary = float(salary)
# 如果输⼊的⼯资为0,结束循环
if salary <= 0:
print('你不⽤交五险⼀⾦,也不⽤交税')
break
# 如果⼯资⼤于或等于7662 五险⼀⾦=7662*五险⼀⾦⽐例(0 .225 # )
if salary >= 7662:
wxyj = 7662 * 0.225
else:
# 如果⼯资⼩于7662,五险⼀⾦ = ⼯资 * 五险⼀⾦⽐例
wxyj = salary * 0.225
# 计算应纳税所得额
# 应纳税所得额=⼯资-五险⼀⾦-起征点(3500)
tax_income = salary - wxyj - 3500
if tax_income < 0:
tax_income = 0
else:
tax_income = tax_income
# 声明两个变量
# 税率
Ladder_rate = 0
# 速算扣除数
quick_deduction = 0
# 判断应纳税所得额所在的阶梯
if tax_income <= 0:
print('您不⽤交税!')
elif tax_income <= 1500:
Ladder_rate = 0.03
elif tax_income <= 4500:
Ladder_rate = 0.1
quick_deduction = 105
elif tax_income <= 9000:
Ladder_rate = 0.2
quick_deduction = 555
elif tax_income <= 35000:
Ladder_rate = 0.25
quick_deduction = 1005
elif tax_income <= 55000:
Ladder_rate = 0.3
quick_deduction = 2755
elif tax_income <= 80000:
Ladder_rate = 0.35
quick_deduction = 5505
else:
Ladder_rate = 0.45
quick_deduction = 13505
# 计算税额
shui_er = tax_income * Ladder_rate - quick_deduction
# print('%.2f'%shui_er)
daoshou_salary = salary - wxyj - shui_er
print('您输⼊的⼯资为%.2f' % salary)
print('五险⼀⾦为:%.2f 应纳税所得额 :%.2f 税额:%.2f 到⼿⼯资为:%.2f' % (wxyj, tax_income, shui_er, daoshou_salary)) def guess_figure():
# 使⽤到python中内置的random模块
# 引⼊random模块
import random
# 随机⽣成⼀个0~100的整数,作为正确答案 包含0和100
number = random.randint(0, 100)
# 在while循环中写代码
count = 0
while 1:
# 输⼊⼀个0~100的整数,input输⼊的时字符串
guess_number = input('请输⼊⼀个数字(0~100):')
# 将输⼊的字符串转换成整数类型
guess_number = int(guess_number)
# 只要输⼊的数字不在0~100的范围,请重新输⼊
while guess_number < 0 or guess_number > 100:
# 重新输⼊
guess_number = input('输⼊的数字不在范围,请重新输⼊:')
# 转换为整数类型
guess_number = int(guess_number)
# 和正确的答案数字做对⽐
if guess_number < number:
print('您猜⼩了!')
elif guess_number > number:
print('您猜⼤了!')
else:
print('恭喜您,猜对了!')
# 如果猜对了,给两个选项,1.继续玩 2.退出
print('0.退出')
print('1.继续玩')
# 输⼊⼀个选项
num = input('请输⼊您的选择:')
num = int(num)
while num not in range(0, 2):
num = input('您的选择不合法,请重新选择(0退出):') num = int(num)
# 继续玩
if num == 1:
# 重置正确答案
number = random.randint(0, 100)
# 猜测次数归零
count = 0
# 跳过当前次的循环,直接执⾏下⼀次的循环
continue
else:
# 结束循环 退出程序
break
count += 1
if count == 5:
print('您的猜测次数⼤于5次,游戏失败!')
break
while 1:
print('1.BMI体重指数计算器')
print('2.出租车费⽤计算器')
print('3.税额计算器')
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论