发布于2022年11月4日4年前 实例1 height = 1.65 print("你的身高:"+str(height)) weight = 45.5 print("你的体重:"+str(weight)) bmi=weight/(height*height) print("你的BMI指数为:"+str(bmi)) #判断身材是否合理 if bmi<18.5: print("你的体重过轻 ~@_@~") if bmi>=18.5 and bmi<24.5: print("正常范围,注意保持(-_-)") if bmi>=24.9 and bmi<29.9: print("你的体重过重 ~@_@~") if bmi>=29.9: print("肥胖 ^@_@^") 实例2 print( '''学编程,你不是一个人在战斗 | __\--__|_ II=======00000[/ ▲007 | _____\______|/-----. /___mingrisoft.com___| \◎◎◎◎◎◎◎◎◎○/ ~~~~~~~~~~~~~~~~~~''') 实例三 money_all=56.7+72.91+88.50+26.37+68.51 money_all_str=str(money_all) print("商品总金额为:"+money_all_str) money_real=int(money_all) money_real_str=str(money_real) print("实收金额:"+money_real_str) 实例四 python=95 English=92 c=89 sub=python-c avg=(python+English+c)/3 print("Python课程和C语言课程的分数之差:"+str(sub)+"分\n") print("3门课的平均分:"+str(avg)+"分") 实例五 python=95 English=92 c=89 print("python="+str(python)+"Ehglish="+str(English)+"c="+str(c)+"\n") print("python<English的结果:"+str(python<English)) print("python>English的结果:"+str(python>English)) print("python==English的结果:"+str(python==English)) print("python!=English的结果:"+str(python!=English)) print("python<=English的结果:"+str(python<=English)) print("English>=c的结果:"+str(python>=c)) 实例六 print("\n手机店正在打折,活动进行中...") strWeek=input("请输入中文星期(如星期一):") intTime=int(input("请输入时间中的小时(范围:0~23):")) #判断是否满足活动参与条件(使用了if条件语句) if(strWeek=="星期二"and(intTime>=10 and intTime<=11))or(strWeek=="星期五" and(intTime>=14 and intTime<=15)): print("恭喜你,获得了折扣活动参与资格,快快选购吧!") else: print("对不起,你来晚一步,期待下次活动..") 实战七 height = float(input("请输入您的身高(单位为米):")) weight = float(input("请输入您的体重(单位为千克):")) bmi= weight/(height*height) print("您的bmi指数为:" + str(bmi)) if bmi<18.5: print("你的体重过轻") if bmi>=18.5: print("你的体重正常") if bmi>=29.9: print("体重过重") if bmi>=29.9: print("肥胖") ’ 实战1 print("欢迎使用crz移动有限公司充值业务,请输入充值金额:") money=int(input("输入数值:")) print("充值成功,您本次充值:",money) 实战2 print(''' ***** * * * @ @ * * * * @ * * * * * ******''') 实战3 faheight=float(input("请输入父亲的身高(单位为米):")) maheight=float(input("请输入母亲的身高(单位为米):")) sonheight=(faheight+maheight)*0.54 print("预测儿子身高为:"+str(sonheight))
创建帐户或登录后发表意见