r/pythonhelp • u/liquidheaven • Jul 15 '23
Why does if < 0 cause a failure in this code?
Line 6:
It prints the failure message then encounters an error and quits.
3
u/WhipsAndMarkovChains Jul 15 '23
It prints the failure message
It prints WHAT failure message? You need to give us the error.
I'm guessing you entered something like "abc", which can't be converted to an integer.
1
u/liquidheaven Jul 15 '23
I am using Replit and the error message looks like this:
The game is guess the number 0-1,000,000
What is your guess? -1
bzzt... game over, no negative!
repl process died unexpectedly:Then it exits
1
u/Zeroflops Jul 15 '23
Looks like it is doing exactly what you’re telling it to do.
The exit command is exiting out of not just the execution but exiting out of the replit python.
1
u/liquidheaven Jul 16 '23
How is it exiting out of replit as well?
I just copied their solution and ran it and when you enter a negative, you get the same error I am receiving so I suppose my answer is as good as theirs but I am curious if you think this could be fixed in my code?
1
u/liquidheaven Jul 15 '23
The code has a function for non integers I believe. That's what the final else is for.
1
u/WhipsAndMarkovChains Jul 15 '23
code has a function for non integers
It does not. Try it and find out.
1
u/liquidheaven Jul 16 '23
I haven't learned the representation for non integers yet. Just int and float so I shouldn't need something different. I just mentioned in another comment above, I copied their solution and ran it and came up with the same exact error message when supplying a negative. I am also curious if you think there's a solution that will not exit replit entirely?
•
u/AutoModerator Jul 15 '23
Note:
This sub went private for a few days recently in solidarity with other subs who are hoping to get Reddit to reconsider some changes that they have proposed. These changes will affect the Reddit API and many third-party apps that access Reddit. If you are not already aware of the proposed changes, please read up on the topic and the ongoing protest.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.