+ 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
4 Answers
+ 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")
0
Hmmmm. Its a tricky one
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.