打印时不断加括号和引号
When printed keeps on putting parentheses and quotations
我正在尝试创建一个制作购物清单然后允许用户设置价格的程序。该程序应该会向您显示您的购物清单,最后根据您给出的价格进行编号。
products = []
product_price = []
add_product = input("Would you like to add an item?: ")
while add_product == "yes":
item = input("Enter the product: ")
products.append(item)
item_price = input("How much does this item cost? ")
product_price.append(item_price)
print(f"{item} has been added to the cart. ")
add_product = input("Would you like to add an item? ")
print("The contents of the shopping cart are: ")
zipobj = zip(products, product_price)
for i, prices in enumerate(zipobj, start = 1):
print(i, prices)
我希望它打印出如下内容:
- 鞋子 - 50 美元
- 连衣裙 - 25 美元
我得到的是:
1 ('shoes', '50')
2 ('dress', '25')
我做错了什么?
谢谢
使用字符串格式来生成您想要的输出:
for i, (item, price) in enumate(zipobj, start=1):
print(f"{i}. {item} - ${price}")
我正在尝试创建一个制作购物清单然后允许用户设置价格的程序。该程序应该会向您显示您的购物清单,最后根据您给出的价格进行编号。
products = []
product_price = []
add_product = input("Would you like to add an item?: ")
while add_product == "yes":
item = input("Enter the product: ")
products.append(item)
item_price = input("How much does this item cost? ")
product_price.append(item_price)
print(f"{item} has been added to the cart. ")
add_product = input("Would you like to add an item? ")
print("The contents of the shopping cart are: ")
zipobj = zip(products, product_price)
for i, prices in enumerate(zipobj, start = 1):
print(i, prices)
我希望它打印出如下内容:
- 鞋子 - 50 美元
- 连衣裙 - 25 美元
我得到的是:
1 ('shoes', '50') 2 ('dress', '25')
我做错了什么?
谢谢
使用字符串格式来生成您想要的输出:
for i, (item, price) in enumate(zipobj, start=1):
print(f"{i}. {item} - ${price}")