Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,424 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! :)