r/PythonLearning • • 17d ago

Help Request Need help understanding how != works

Hello, I'm working on learning the basics of try/except blocks. To do so, I'm intentionally raising errors. The question is: why is my TypeError occurring when I enter an integer? I checked the input type, and it shows as an integer, but the error is still raised. What am I missing here?

31 Upvotes

17 comments sorted by

View all comments

9

u/BanSolitude 17d ago

Your original question has been answered, but I will point out that your code as written will never hit line 25. int(...) will raise an exception if you pass in a value that cannot be converted to an integer, if the code makes it to line 24 then carsAvailable must be an integer, and the check is redundant.

1

u/The-Turnt-Tiger 17d ago

I see what you're saying. I'm using the raise to help visualize what's happening while I try to understand how this works. Thank you for pointing that out though.

4

u/Scared-Letterhead949 17d ago

But the raise isn't helping because it'll never fire.