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

Why is my code not working?

TICKET_PRICE = 10

tickets_remaining = 100  

# Output how many tickets are remaining using the tickets_remaining variable
print("There are {} tickets remaining.".format(tickets_remaining))


# Gather the users name and assign it to a new variable
name = input("What is your name: ")

# Prompt the user by name and ask how many tickets they would like

# Calculate price (Number of tickets multiplied by TICKET_PRICE) and assign it to a variable

#Output price to the screen

num_tickets = input("How many tickets would you like, {}? ".format(name))
num_tickets = int(num_tickets)

amount_due = num_tickets * TICKET_PRICE

print("That will cost you" + amount_due)

Mod note - Added Forum Markdown so we can read the code better. Check out the cheat sheet and the Markdown course on Treehouse :)

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

It looks like you're to coerce the response of the of num_tickets into an integer but it is still expecting a string. Instead of concatenating the last line, use a formatted string as you did before with the format method.

Phil Thomas
Phil Thomas
4,563 Points

Hi, I'm also learning, but starting to get my head round the concepts. Looking at your code helped me realise that I had asked how many tickets they wanted and not converted their input into an integer (as you do in your code). You seem to have made the same mistake with not converting the integer in the final line into a string, so you're trying to append an integer with a string. I also think you can refactor a bit of your code with the variable num_tickets, by taking making the user's input an integer at the point you receive it.

I don't know if that makes sense, but here's how I've amended your code and it now appears to work. Thanks for sharing your code, it helped me realise my own errors and get to the end of this section

TICKET_PRICE = 10

tickets_remaining = 100  

# Output how many tickets are remaining using the tickets_remaining variable
print("There are {} tickets remaining.".format(tickets_remaining))


# Gather the users name and assign it to a new variable
name = input("What is your name: ")

# Prompt the user by name and ask how many tickets they would like

# Calculate price (Number of tickets multiplied by TICKET_PRICE) and assign it to a variable

#Output price to the screen

num_tickets = int(input("How many tickets would you like, {}? ".format(name)))

amount_due = num_tickets * TICKET_PRICE

print("That will cost you " + str(amount_due))
Eddie Licea
Eddie Licea
1,610 Points

Your code was fine I just changed the last line a bit.

TICKET_PRICE = 10
tickets_remaining = 100  
print("There are {} tickets remaining.".format(tickets_remaining))
name = input("What is your name: ")
num_tickets = input("How many tickets would you like, {}? ".format(name))
num_tickets = int(num_tickets)
amount_due = num_tickets * TICKET_PRICE
print("That will cost you {}".format(amount_due))   <<<<<

Your mistake was here at the end

print("That will cost you" + amount_due)

You wanted to add a string to an int. No can do :). Just implemented the .format and your code worked perfectly. Have a good one my friend.

print("That will cost you {}".format(amount_due))