+ 2

I need help with my guessing game.

Python code where you have to guess the number in 6 guesses. https://code.sololearn.com/cOm93iUf67Xc/?ref=app

10th Nov 2017, 2:12 PM
Chantel Sethosa
Chantel Sethosa - avatar
4 ответов
+ 13
#Ive modified it a bit.. I'm new to python too.. hope its correct from random import randint print("whats your name ?") #type in your name Name= input() print("hi"+Name+"lets play a game") print("guess a number between 1 and 20") Number = randint(1,20) guesses_taken=0 while guesses_taken < 6: print("take another guess") Guess=input() Guess=int(Guess ) guesses_taken += 1 if Guess == Number: print("You guessed correctly in "+guesses_taken+"guesses") break elif Guess != Number: print ("oh sorry thats the wrong number,try again") if Guess !=Number: Number = str(Number ) print ("the number i was think of is "+Number+" thank you for playing")
10th Nov 2017, 3:12 PM
Frost
Frost - avatar
13th Nov 2017, 1:22 PM
Chantel Sethosa
Chantel Sethosa - avatar
0
Hmmmm. Its a tricky one
10th Nov 2017, 3:01 PM
greelpy
0
@Frost: On the 10th line, because the way python reads code, it will read guesses_taken first, and since that has not been defined, it comes up with an error. Try assigning it to 0 the line before.
11th Nov 2017, 4:13 AM
privrax.
privrax. - avatar