读书笔记

发布时间 2023-11-01 01:14:36作者: 李森阳

# 超市收银抹零

# 尝试对金额四舍五入输出

# 根据提示语键盘输入数字
money = float(input('请输入收银金额(元):'))

# 类型转换,并打印
print('抹零后金额为(元):' + str(int(money)))

----------------------------------------------------------------
#04计算学生成绩的分差和平均分
a = int(input("请输入第一个学生的成绩:"))
b = int(input("请输入第二个学生的成绩:"))
c = abs(a-b)
d = (a+b)/2
print("两个学生的分差为:{}".format(c))
print("两个学生的平均分为:{}".format(d))
---------------------------------------------------------------
#05比较运算符比较大小关系
a = int(input("请输入第一个数:"))
b = int(input("请输入第二个数:"))
if a>b:
print("bingo")
else:
print("no")
------------------------------------------------------------
#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("对不起,您来晚一步,期待下次活动...")
------------------------------------------------------------------
#新建一个文件,并保存一段话。2.6.2
def create_file_and_check_content(filename):
# 创建文件并写入内容
with open(filename, "w") as file:
file.write("2.6.2")

# 判断文件内容是否已写入
try:
with open(filename, "r") as file:
content = file.read()
if content == "2.6.2":
print("文件内容已写入")
else:
print("文件内容未写入")
except FileNotFoundError:
print("文件未创建")
# 调用函数并传入文件名参数
create_file_and_check_content("test.txt")
---------------------------------------------------------------
print("学号后四位为3113")

 

 

运行结果