代码如下:
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
1
#!/usr/bin/env python3.6def due(cost):
if cost >= 3000:
return cost * 0.85
if cost >= 2000:
return cost * 0.9
if cost >= 1000:
return cost *0.95
return cost
cost = input('Please input total cost of the goods: ')
print(f'You should pay: {due(float(cost)):.2f}')
2
a, b, c = 1, 2, 3n = 3
while True:
n += 1
a, b, c = b, c, (a+b+c)/2.0
if c > 1200:
print(n)
break
3
def gys(m, n):for i in range(min(m, n), 0, -1):
if m % i == n % i == 0:
return i
4
def is_wanshu(n):yinzi = [i for i in range(1, n) if n % i == 0]
return n == sum(yinzi)