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
203,993 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).