Python Python Basics All Together Now Gather Information

Deonte Meriwether
Deonte Meriwether
1,361 Points

Masterticket price error

When I run the following code the results print the price incorrectly. For example if the person wants 3 tickets it prints the number "3" ten times like "3333333333" instead of 30. I don't know where I went wrong please help! :)

TICKET_PRICE = 10

tickets_remaining = 100

print("There are {} tickets remaining".format(tickets_remaining))

user_name = input("What is your first name? ")

number_of_tickets = input("Hello {}, how many tickets would you like? ".format (user_name))

price = (TICKET_PRICE * number_of_tickets)

print (price)

1 Answer

Steven Parker
Steven Parker
171,327 Points

In Python, the asterisk can be a multiply operator when used with numbers, or a "repeat" operator when used with a number and a string. The behavior you are seeing is the "repeat" of the string read in by the "input" statement.

Just convert the string to a number (perhaps using "int()") to get the multiply behavior.

Deonte Meriwether
Deonte Meriwether
1,361 Points

Oh yeah that's right I totally forgot about that! Thank you Steven! :)