代码如下:
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
'''
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)