用python编写程序,对顾客购买的商品,让数量大于等于5件时,打八折,求总价

用python编写程序,对顾客购买的商品,让数量大于等于5件时,打八折,求总价,第1张

代码如下:

price = input("请输入商品价格以空格分割:").strip()

price = list(map(int,price.split(' ')))

amount = len(price)

if amount >= 5:

print(f"购买了{amount}件商品,享受八折优惠。优惠后的价格为:{sum(price)*0.8},优惠金额为:{sum(price)*0.2}")

else:

print(f"购买了{amount}件商品。总价为:{sum(price)}")

输出如下:

x,y=input("(单价@数量):x@y=").split("@")

try:

float(x)*float(y)

except Exception as err:

print(err)

else:

result=float(x)*float(y)

print(f"总价={result}")

'''

(单价@数量):x@y=12@k

could not convert string to float: 'k'

(单价@数量):x@y=k@8

could not convert string to float: 'k'

(单价@数量):x@y=12.36@89

总价=1100.04

'''


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11966596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存