代码如下:
price={"apple":5,"peach":6,"banana":3,"pear":4}
print("today's fruit price")
furit=int()
num=int()
for furit in price:
print("%s %d yuan/jin"%(furit,price[furit]))
print("")
n=int(input("pls input what many types of fruits you want to buy:"))
sum_price=0
for i in range(0,n):
fruit=input("input the name of fruit%d:"%(i+1))
if fruit in price:
sum_price+=price[fruit]*num
num=int(input("input the quantity%d of fruit:"%(i+1)))
else:
print("the %s is not on-sell"%(furit))
print("total price is %d"%(sum_price))
输入orange之后,应该是the orange is not on-sell, 但却打印出pear:
today's fruit price
apple 5 yuan/jin
peach 6 yuan/jin
banana 3 yuan/jin
pear 4 yuan/jin
pls input what many types of fruits you want to buy:4
input the name of fruit1:apple
input the quantity1 of fruit:1
input the name of fruit2:orange
the pear is not on-sell
input the name of fruit3: