Python小项目2

127 阅读1分钟
原文链接: mp.weixin.qq.com

  • 百分制成绩转等级制成绩

    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)/2    area = 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 = 0    deduction = 0elif diff < 1500:    rate = 0.03    deduction = 0elif diff < 4500:    rate = 0.1    deduction = 555elif diff < 9000:    rate = 0.2    deduction = 555elif diff < 35000:    rate = 0.25    deduction = 1005elif diff < 55000:    rate = 0.3    deduction = 2755elif diff < 80000:    rate = 0.35    deduction = 5505else:    rate = 0.45    deduction = 13505# abs()函数取绝对值tax = abs(diff * rate - deduction)print('个人所得税: ¥%.2f元' % tax)print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax))