习题求解
n = int(input("输入商品数:"))d = {} #字典
s = 0 #总价
h = -1 #最高商品价值
name = None #最高商品价值的名字
for i in range(n):
sname = input(f"输入第{i + 1}个商品的名字:")
price = int(input("输入这个商品的价格:"))
s += price
d = price
if price > h:
h = price
name = sname
print("商品字典:", d, "价格平均值:{:.2f}".format(round(s / n, 2)), "价格最高商品名:", name, sep = "\n")
页:
[1]