Home > Back-end >  When printed keeps on putting parentheses and quotations
When printed keeps on putting parentheses and quotations

Time:11-14

I am trying to create a program that makes a shopping list and then allows the user to set the price. The program is supposed to show you your shopping list numbered with the price you gave it at the end.

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)

I want it to print something like:

  1. shoes - $50
  2. dress - $25

What I get instead is:

1 ('shoes', '50') 2 ('dress', '25')

What am I doing wrong?

Thanks

CodePudding user response:

Use string formatting to produce the output you want:

for i, (item, price) in enumate(zipobj, start=1):
    print(f"{i}. {item} - ${price}")
  • Related