0

Guess the number game

import random guesstaken=0 print('what is your name') myname=input() number=random.randint(1,20) print('well !',myname,'i am thinking a number between 1 and 20') print('guess the number') for guesstaken in range(6): guess=int(input()) if guesstaken not in range(0,20): print('No! :(',myname,'please guess a number between 0 and 20 :)') #if guesstaken>number: print('Hey!',myname,'your number is too high please take another chance') #if guesstaken<number: print('Hey!',myname,'your number is too low please take another chance') if guesstaken==number: break print('wow !',myname,'you win :)') This is my first game code and i am learning how to code any game through python and this code run but when I enter a number greater than the number which is given in 'random.randint(0,20)' it show your number is too low take another chance but i want to my game show the statement ' please guess the number between 0,20' helpšŸ™šŸ™šŸ™

27th Sep 2022, 1:01 PM
Hamilton Jersey
Hamilton Jersey - avatar
5 Answers
+ 4
Please LINK YOUR CODE. That way it is more readable and people can actually test it. How to: šŸ‘‰šŸ‘‰GO TO Code section, click +, select the programming language, insert your code and save it. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
27th Sep 2022, 1:22 PM
Lisa
Lisa - avatar
+ 3
* Compare the number to guess, not to guesstaken * guess needs to be an integer, not a string * On the first if-statement: Check if guess is in the range that you used for sampling number, not in the range of [0;6)
27th Sep 2022, 5:20 PM
Lisa
Lisa - avatar
+ 2
I entered Lisa 1 2 3 4 5 6 There was no error. On sololearn you have to provide all inputs in the beginning. Separate multiple input by line breaks beforeyou click Submit. Read the text in the pop-up window.
27th Sep 2022, 5:13 PM
Lisa
Lisa - avatar
0
https://code.sololearn.com/c5jeEKHIz29L/?ref=app This show EOF error at line 13 but when I run in pydroid3 app it show nothing i am indentation also plzz helpšŸ™šŸ™
27th Sep 2022, 5:10 PM
Hamilton Jersey
Hamilton Jersey - avatar
0
The print in line 26 is after a break statement, so will never run
28th Sep 2022, 3:39 AM
Emerson Prado
Emerson Prado - avatar