First I like to thank everyone that helped me with my work...

Please bear with me I don't know how to explain my problem.
Trying to get the random number to remain the same through out the length of the program. When the player guess the right number the player clicks on "Y" and the number should change. Cant get the number to change inside the loop. Outside the loop it changes every time a guess is made. I had a couple of while loops under the initial one but I opted for the if and elif.

import random

def main():
    answer = 'y'
    
    while answer == 'y' or answer == 'Y':
        number = random.randint(1, 1000)
        print 'I have a number between 1 and 1000'
        print 'Can you guess the right number'
        print number 
        guess = input('Enter  your number')
        
        if number > guess:
            print "Too low.  Guess again"
            guess
        elif number < guess:
            print "Too high.  Guess again"
            guess
        elif number == guess:
            print 'You won!!!'
            answer = raw_input("Do you want to play again? (Enter y for yes): ") 
main()

Try this:

All i did was put a random number at the start of main and when they guess the correct number

import random

def main():
    answer = 'y'
    number = random.randint(1, 1000)
    while answer == 'y' or answer == 'Y':
        
        print 'I have a number between 1 and 1000'
        print 'Can you guess the right number'
        print number 
        guess = input('Enter  your number')
        
        if number > guess:
            print "Too low.  Guess again"
            guess
        elif number < guess:
            print "Too high.  Guess again"
            guess
        elif number == guess:
            print 'You won!!!'
            number = random.randint(1, 1000)
            answer = raw_input("Do you want to play again? (Enter y for yes): ") 
main()

I was using another IDE so I was getting errors. I popped it back into IDLE and it works fine.

This question has already been answered. Start a new discussion instead.