实战练习
实例三:
money_all = 56.75 + 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("43014实收金额为:"+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门课3014的平均分:" + str(avg) + "分")
结果是:

实例五:
python = 95
english = 92
c = 89
print("python = " + str(python) + "english = " + 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 <= englsih的结果:" + str(python <= english))
print("english >= c的结果:" + str(python >= c))
结果是:

实例六:
print("\n手机店正在打折,活动进行中....")
strweek = input("请输入中文星期(如星期一):")
inttime = int(input("请输入时间中的小时(范围:0~23):"))
if(strweek == "星期二" and (inttime >= 10 and inttime <= 11))or(strweek == "星期五" and (inttime >= 14 and inttime <=15)):
print("43014恭喜您,获得了折扣活动参与资格,快快选购吧!")
else:
print("43014对不起,您来晚一步,期待下次活动~")
结果是:

2.6.2
fp = open(r'D:\mot.txt,','a+')
print("命运给予我们的不是失望之酒,而是机会之杯。",file=fp)
fp.close()


浙公网安备 33010602011771号