So I'm new to this programming thing... But this has me stumped. To the point that I'm wondering if the website I'm running Python on is wrong. (repl.it is the website).
So I did one of those guess the number games as a small fun challenge. This is the code that I came up with:
from random import randint print ("Welcome to guess the number!") answer = str(randint(0,100)) print (answer) print () def something(): answerTwo = str(randint(0,100)) print (answerTwo) idea(answerTwo) def idea(x): number = str(input("Guess a number between 0 and 100:")) if number != x: if (number > x): print() print(number + " is too high!") print() idea(x) elif (number < x): print() print(number + " is too low!") print() idea(x) else: print() print ("That is correct!") again = input("Would you like to play again?:") if again == "yes": something() else: print ("Thanks for playing!") idea(answer) On the 4th and 8th line I print out the random number chosen so that I can quickly test to make sure everything works. Then I removed the print functions in the final product and tested again. Except when I removed the print functions it stopped working after some amount of time. For example, it'll say 39 is too low but 40 is too high, which is impossible since they're is no number in between them. If you put the print functions back in it works again, but remove them and it'll start acting up eventually.
I apologize if it's something really obvious but I just don't understand how this is possible.
Here is the github thingy for it
https://gist.github.com/anonymous/4a370664ae8ddb29aec5915eb20e686f
Thanks for your time!
numberis astrit won't be doing a numerical comparison.str()(sincerandintreturns integers and you can still do the numeric comparison with the user inputs), which will also change theprint()statements a bit (use string formatting to print the numbers, sinceprint()won't concatenate strings and integers. Here's your code modified so it should behave the way you are expecting: repl.it/HvaN/0 , hope it helps.