Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics All Together Now Gather Information

Deonte Meriwether
Deonte Meriwether
1,513 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
229,657 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,513 Points

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