*忽略这一部分,只看最后几个代码。我试图将所有量子加在一起,但最后一个代码单独打印每个购买?我怎样才能打印出来#34;你的购买是"并在一行中添加量子乘以它们的价格,而不是为每个人打印它
print "Enter a fruit name (or done):",
fruit = raw_input()
fruit_list = []
while fruit != "done":
fruit_list = fruit_list + [fruit]
print "Enter a fruit name (or done):",
fruit = raw_input()
price_list = []
for x in range(0, len(fruit_list)):
print "Enter the price for " + fruit_list[x] + ":",
price = float(raw_input())
price_list = price_list + [price]
# print " Your fruit list is:" + str(fruit_list)
# print "Your price list is:" + str(price_list)
print fruit_list
print price_list
quanity_list = []
for x in range(0, len(fruit_list)):
print str(fruit_list[x]) + str(price_list[x]) + " Quantity:",
quantity = int(raw_input())
print "Your total purchase is:", + price_list[x] * quantity
答案 0 :(得分:0)
请尝试以下代码: 替换你的最后一部分代码;
total = 0
quanity_list = []
for x in range(0, len(fruit_list)):
print str(fruit_list[x]) + str(price_list[x]) + " Quantity:",
quantity = int(raw_input())
total = total + price_list[x] * quantity
print "Your total purchase is:" + total