jeudi 7 mai 2015

Python guessing game not working

I am making a python code that picks a random number and compares it to a guess made by the user.

import random
attempts=0
secret=random.randint(1,49)
print "welcome to my guessing game"
repeat
def repeat():
    guess=raw_input("I have thought of a number between 1 and 50. you have to try and guess it")
        if secret==guess:
            print "Well Done! you guessed it in "+attempts+" attempts"
        elif secret < guess:
            print "too high"
            guess=raw_input("have another go")
        elif secret > guess:
            print "too low"
            guess=raw_input("have another go")
    attempts += 1
while guess != secret and attempts>6:
    repeat()

but it is saying that repeat is not defined.




Aucun commentaire:

Enregistrer un commentaire