栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 分支结构习题

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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")
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/982898.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号