练习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")