Sep-16-2016, 04:18 PM
Not sure if it's the new code button that removed all the indents, but we'll see. I've added indents and notes to your code so you can follow what I did.
#Guess Random Number #Generate a Random number between 0 to 9 import random turn = 0 def guessRandom(): secretNumber = random.randint(0,9) return secretNumber # Return a value for guessRandom a_num = guessRandom() # Get a value from guessRandom and assign it to a_num print(a_num) # We want to cheat and see what the number is :-) while True: guessNumber = int(input("Guess a Random number between 0-9 ")) if a_num == guessNumber: print("you Have Guessed it Right!") turn += 1 # We can simplify the term 'turn = turn + 1' break # We're done so break out of the 'while' loop and go to next command elif a_num > guessNumber: # Need to change this from 'higher' to 'lower' input("You have Guessed the number lower than secretNumber. Press Enter to Guess Again!") turn = turn + 1 continue # Go back to start of 'while' elif a_num < guessNumber: # Need to change this from 'lower to higher' input("You have guessed the number higher than secretNumber. Press Enter to Guess Again! ") turn = turn + 1 continue # Go back to start of 'while' print("Turn = ", turn)In the future, the is a "code" button (6th button from the right) on the format bar :)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition