用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)}")

输出如下:

#首先设置未知数

amount = 0

total_cost = 0

money_saved = 0

#设置输中搭斗入

price = input (“输入价格”:)

while price >0:

total_cost = total_cost + price

amount +=1

if amount <4:

total_off = total_cost * (1- amount/10.00)

#如果有变量

else:

total_off = total * 0.6

money_saved = total_cost - total_off

#输出价格,节省的金额和,实际支付的卖磨价格

print "几件物品: ",amount

print "总支付(¥): "枝差,total_off

print "节省金额¥" , money_saved

#set the variables

amount = 0

money_saved = 0

total_cost = 0

price = input("段磨Enter the price of the bread until entered you entered 0: ")

#while statement

while price >0:

total_cost = total_cost + price

amount +=1

price = input("Enter the price of the bread untiled you entered 0: ")

if amount <3:

total_off = total_cost * (1- amount * 0.1)

#if the amount of the bread is more than 3

else:

total_off = total_cost * 0.7

money_saved = total_cost - total_off

#print the total cost, and money saved

print "埋戚Total cost after the discount is: ", total_off

print "弯燃陵You saved: ", money_saved


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存