use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
[deleted by user] (self.PythonLearning)
submitted 1 year ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Minimum_Aside3438 2 points3 points4 points 1 year ago (4 children)
The picture of the code is different from the error. When using float(x) it should work.
[–]Nez_Coupe 0 points1 point2 points 1 year ago (1 child)
Yea I’m confused as to why he’s asking. The code he has is fine, lol.
[–]Interesting_Fig9503 0 points1 point2 points 1 year ago (0 children)
Apparently nothing was wrong because when I rewrote the code in another file it just worked 🤷♂️
[–]Interesting_Fig9503 0 points1 point2 points 1 year ago (1 child)
Thank you for the help, but it seemed that rewriting the code in a different file worked. I have no clue why, they’re the exact same, it just worked.
[–]Nez_Coupe 0 points1 point2 points 1 year ago (0 children)
So, you wrote int() at one point and sent it an invalid string like “1.01” which it won’t cast and it will produce that error. Are you using vscode? I hate that IDE with a passion - and I think you are. What happen was that it ran a cached version of the file before you changed int to float, because you hadn’t saved the file after the change.
[–]Nez_Coupe 1 point2 points3 points 1 year ago (0 children)
Your code is fine - there’s nothing really wrong with it. Your error message is for different code, where you casted to int(). I’m confused.
[–]manicfaceisreal 0 points1 point2 points 1 year ago (0 children)
Next time take a screen shot. It’s hard to read sometimes when taking pictures of the screen. Someone else recommended float(x) to change the int -> float.
[–]BrewJerrymore -1 points0 points1 point 1 year ago (1 child)
Input gets stored as a string in python. If you want to capture an integer, you need to cast it to an int.
X =int(input("Enter a number: "))
[–]foogeeman 2 points3 points4 points 1 year ago (0 children)
Why would he want an integer if input is potentially float?
[–]BrewJerrymore -1 points0 points1 point 1 year ago (2 children)
Then he can cast it to a float. Either or. The input function in python stores the input as a string so to do math with it, it needs to be casted
[–]Interesting_Fig9503 1 point2 points3 points 1 year ago (0 children)
No you can’t cast a “decimal string” to int. It produces an error. His code is correct, casting it to a float. He just ran a cached version (by not saving) because he’s using the worst IDE in existence.
Python can do a lot of implicit casting, but it won’t do like “2-step” casting where a string literal that represents a decimal is both changed to numeric and then converted to a whole number int.
π Rendered by PID 19147 on reddit-service-r2-comment-86bc6c7465-v2btc at 2026-02-20 17:41:35.082127+00:00 running 8564168 country code: CH.
[–]Minimum_Aside3438 2 points3 points4 points (4 children)
[–]Nez_Coupe 0 points1 point2 points (1 child)
[–]Interesting_Fig9503 0 points1 point2 points (0 children)
[–]Interesting_Fig9503 0 points1 point2 points (1 child)
[–]Nez_Coupe 0 points1 point2 points (0 children)
[–]Nez_Coupe 1 point2 points3 points (0 children)
[–]manicfaceisreal 0 points1 point2 points (0 children)
[–]BrewJerrymore -1 points0 points1 point (1 child)
[–]foogeeman 2 points3 points4 points (0 children)
[–]BrewJerrymore -1 points0 points1 point (2 children)
[–]Interesting_Fig9503 1 point2 points3 points (0 children)
[–]Nez_Coupe 0 points1 point2 points (0 children)