Python 分支结构习题

练习1:输入三条边长,如果能构成三角形就计算周长和面积。

A=float(input("input A"))
B=float(input("input B"))
C=float(input("input C"))
if (A + B > C) and (A + C > B) and (B + C > A) :
    Primiter=A+B+C
    P=(A+B+C)/2
    S=(P*(P-A)*(P-B)*(P-C))**0.5
    print(f"周长{round(Primiter,3)},面积 {round(S,3)}")
else:
    print('不够成三角形')


练习2:百分制成绩转换为等级制成绩。

score = int (input(" please input a score "))
if score>=90:
    print("A")
elif 90>score>=80 :
    print("B")
elif 80>score>=70 :
    print("C")
elif 70>score>=60 :
    print("D")
elif  score<60:
    print("E")

练习3:英制单位英寸和公制单位厘米互换。

num = float(input("please input a number "))
unit = input(" please input a unit")
if unit== "cm" :
    inch= num /2.54
    print(f"{num}cm is equal to {inch}inch")
elif unit == "inch":
     cm = num*2.54
     print(f"{num}inch is equal to {cm}cm")
else:
    print("please input valid unit")
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值