Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Guess Random Number Why i m not able to enter input Nithya Thiyagarajan Unladen Swallow Posts: 1 Threads: 1 Joined: Sep 2016 Reputation: 0 Likes received: 0 #1 Sep-16-2016, 12:37 PM (This post was last modified: Sep-16-2016, 02:07 PM by Yoriz. Edit Reason: First post lock. Please use code tags to post code ) Below is my code to generate random number between 0 - 9 and checking with user input whether it is higher lower or equal when I run the code, it is not taking input and showing error in ```guessNumber = int(input("Guess a Random number between 0-9"))                                                                                                   File "", line 1```                                           Can somebody please tell me where I m making mistake :dodgy: :s :s :s :s ```#Guess Random Number #Generate a Random number between 0 to 9 import random turn = 0 def guessRandom(): secretNumber = random.randint(0,9) guessNumber = int(input("Guess a Random number between 0-9")) while secretNumber != guessNumber: if(secretNumber > guessNumber): input("You have Guessed the number higher than secretNumber. Guess Again!") turn = turn + 1 elif (secretNumber < guessNumber): input("You have guessed the number lower than secretNumber. Guess Again! ") turn = turn + 1 if(secretNumber == guessNumber): print("you Have Guessed it Right!") guessRandom()``` nilamo Last Thursdayist Posts: 3,257 Threads: 87 Joined: Sep 2016 Reputation: 133 Likes received: 731 #2 Sep-16-2016, 03:26 PM There's no whitespace in your code. That's unrelated to your error, but it's hard to help when I'm not looking at the same thing you are. sparkz_alot Da Bishop Posts: 1,298 Threads: 32 Joined: Sep 2016 Reputation: 30 Likes received: 268 #3 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 ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 272 Likes received: 1264 #4 Sep-16-2016, 06:14 PM The full text of the error you get would also be useful. The code looks okay at first glance, but using int indiscriminately on input could easily cause errors depending on what the user types in. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures RandomCoder Programmer named Tim Posts: 15 Threads: 7 Joined: Jan 2018 Reputation: 0 Likes received: 0 #5 Jan-07-2018, 01:56 AM you didn't indent correctly This is how I did it but I had a bit of problems with it ```guessnumber=0 import random Mystery = random.randint(0,9) while guessnumber==int(input("Guess a number between 0-9: ")): if guessnumber > Mystery: print('The number you input is not the mystery number, try again.') guessnumber = int(input("Enter a guess: ") if guessnumber == Mystery: ``` Larz60+ aetate et sapientia Posts: 9,055 Threads: 326 Joined: Sep 2016 Reputation: 389 Likes received: 1183 #6 Jan-07-2018, 02:03 AM Indentation is still incorrect. squenson Wafer-Thin Wafer Posts: 87 Threads: 1 Joined: Dec 2017 Reputation: 7 Likes received: 14 #7 Jan-07-2018, 04:26 AM On line 9, you miss a closing parenthesis at the end of the line. On line 10, the indent is incorrect. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post if the input is not number, let user input again teatea 14 342 Yesterday, 07:03 PM Last Post: ibutun Get input directly as a number? Pedroski55 4 238 May-05-2020, 04:29 PM Last Post: deanhystad Guess the word game help jackthechampion 1 191 Mar-30-2020, 01:01 AM Last Post: deanhystad Generate only one random number for many tries Bhavika 2 124 Mar-29-2020, 12:12 PM Last Post: Bhavika Finding MINIMUM number in a random list is not working Mona 5 355 Nov-18-2019, 07:27 PM Last Post: ThomasL Find Average of User Input Defined number of Scores DustinKlent 1 277 Oct-25-2019, 12:40 AM Last Post: Larz60+ How to recognize space or enter as one-character input? Mark17 5 346 Oct-17-2019, 08:19 PM Last Post: jefsummers same number everytime when using random.randint summeringpainting 5 892 Aug-23-2019, 11:01 AM Last Post: Malt help cant do random number nonzzo 1 476 Mar-28-2019, 07:33 PM Last Post: Yoriz problems with random number/string PrasadPython 3 481 Mar-01-2019, 06:00 PM Last Post: ichabod801

Forum Jump:

Users browsing this thread: 1 Guest(s)