Q:

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.

A:

This will allow the user to guess 7 times, then prints game over:
this is for Python 2. for Python 3. use int(input(""))
import random

secret = random.randint(1,49)
attempts = 0
for attempts in range(7):
    guess=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 "
    elif secret < guess:
        print "too high"
        guess=input(" Enter to have another go")
    elif secret > guess:
        print "too low"
        guess=input("Enter to have another go")
    if attempts == 6:
        print "Game Over"

