
百分制成绩转等级制成绩
90分以上 --> A 80分~89分 --> B 70分~79分 --> C 60分~69分 --> D 60分以下 --> E
score = float(input('请输入成绩: '))if score >= 90: grade = 'A'elif score >= 80: grade = 'B'elif score >= 70: grade = 'C'elif score >= 60: grade = 'D'else: grade = 'E'print('对应的等级是:', grade)
-
判断输入的边长能否构成三角形如果能则计算出三角形的周长和面积import matha = float(input(' a = '))b = float(input(' b = '))c = float(input(' c = '))# 两边之和大于第三边if a+b>c and a+c>b and b+c>a:print('周长%f'%(a+b+c))# math模块的sqrt函数来计算平方根# 在这里使用海伦公司求三角形面积p = (a+b+c)/2area = math.sqrt(p*(p-a)*(p-b)*(p-c))print('面积%f'%area)else:print('不能构成三角形')
-
输入月收入和五险一金计算个人所得税deduction 扣除salary = float(input('请输入本月收入'))insurance = float(input('五险一金'))diff = salary - insurance - 3500if diff <= 0:rate = 0deduction = 0elif diff < 1500:rate = 0.03deduction = 0elif diff < 4500:rate = 0.1deduction = 555elif diff < 9000:rate = 0.2deduction = 555elif diff < 35000:rate = 0.25deduction = 1005elif diff < 55000:rate = 0.3deduction = 2755elif diff < 80000:rate = 0.35deduction = 5505else:rate = 0.45deduction = 13505# abs()函数取绝对值tax = abs(diff * rate - deduction)print('个人所得税: ¥%.2f元' % tax)print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax))