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

Input problem

It is really strange that when in my code, when I make the line, that asks about number of tickets user wanna buy : t_request = input("How many tickets would you like to buy? ") t_request = int(t_request)

... and when I start playing around it and type some random float number instead of an integer, lets say (4.5), It pops out ValueError for me when python runs the code, but when I do the exact same thing in python shell - int(4.5), it outputs to me "4" as it should, without giving me any errors, I know that noone ever will type a float number in the t_request line, but I am really confused about why that happens.

1 Answer

Steven Parker
Steven Parker
231,248 Points

Since "t_request" is a string then, int(4.5) is not the "exact same thing".

The equivalent of   int(t_request)   would be   int("4.5")   (with quotes).