蓝螃蟹Karry0921

导航

Python第二章读书笔记

03运行超市抹零结账行为

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("实收金额为:" + money_real_str)

 

04计算学生成绩的分差和平均分

python = 95
english = 92
c = 89
sub = python - c
avg = (python + english +c) / 3
print("Python课程和C语言课程的分数之差:" + str(sub) + " 分\n")
print("3门课的平均分:" + str(avg) + " 分")

 

05比较运算符比较大小关系

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 <= english的结果:" + str(python <= english))
print("english >= c的结果:" +str(python >= c))

 

 06手机店打折活动

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("恭喜您,获得了折扣活动参与资格,快快选购吧!")
else:
print("对不起,您来晚一步,期待下次活动……")

 

 新建一个文件,并保存一段话

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

 

fp = open(r'D:\mot.txt','a+')
print("很开心在第二周的作业学习到了很多新的知识,也让我明白了一个道理,代码要多敲,题要多看,函数要多记多理解。",file=fp)
fp.close()

 

 作者:蓝螃蟹Karry0921

 学号:3039

 

posted on 2021-09-15 00:27  蓝螃蟹Karry0921  阅读(58)  评论(0编辑  收藏  举报