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 Handle Exceptions

Ruben Arellano
Ruben Arellano
732 Points

"Invalid literal" when entering a character into a int question

Whenever I put a character into the "how many tickets" prompt, I get this "invalid literal". Any idea what am I doing wrong?


try: tix_purchase = int(input("Hello {}.\n How many tickets would you like? ".format(name))) if ( tix_purchase > tickets_remaining ) : raise ValueError (" We don't have {}.".format(tickets_remaining)) except ValueError as err: print ("Uh oh! Invalid entry . {} Please try again.".format(err))


Please enter your name ruben
Hello ruben.
How many tickets would you like? jk
Uh oh! Invalid entry . invalid literal for int() with base 10: 'jk' Please try again.
There are 100 tickets available

1 Answer

Asher Orr
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,022 Points

Hi Ruben! You are seeing that error because of this line of code:

 tix_purchase = int(input("Hello {}.\n How many tickets would you like? ".format(name))) 

Specifically this:


That says "Python, what my user inputs/enters is going to be an integer! Throw an error if they enter anything that isn't an integer."

Since "jk" is a string, and not an integer, Python raised that ValueError.

Does that make sense?

PS- check out the markdown cheatsheet for syntax examples on how to format your post. It will make your code easier to read!