第二章读书笔记(作业)

发布时间 2023-10-31 18:43:50作者: Ayers_Lynn

代码如下:


 

def main():
try:
money = float(input("请输入金额:"))
print("抹零后的金额:{}".format(int(money)))
except:
print("请输入数字!")
# 超市抹零#
try:
import math
a = float(input("输入学生a的成绩:"))
b = float(input("输入学生b的成绩:"))

difference = abs(a - b)
average = (a + b) / 2

print("分差:{}.".format(difference))
print("平均成绩:{}.".format(round(average, 2)))
except:
print("请输入数字!")
# 学生成绩平均分及分差#
try:
n = eval(input("请输入n的值:"))
m = eval(input("请输入m的值:"))
print("n>m:", n > m)
print("n<m", n < m)
print("n=m", n == m)
except:
print("请输入数字!")
# 关系运算符#
try:
price = int(input("请输入手机原价:"))
count = int(input("请输入折扣数:"))
if 10 < count < 100:
price = price * count / 100
print("手机价格为:{}".format(price))
else:
print("请输入正确的折扣数!")
except:
print("请输入数字!")
# 手机店打折#
import os
file = open('D:\\新建文件夹.txt', 'w')
file.write("2.6.2")
file.close()
# 新建文件并写入一段话#


def number():
print("学号后四位:3129")


number()
main()



运行截图: