Python Forum

Full Version: Need help with the while function(Beginner)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while guess_count<guess_most:
        answer=input('Guess a number ')
        guess_count+=1
        if str(answer)==str(winning_number):
            print('Correct!')
            break
I know this is a very simple problem but as I stated in the thread subject, I am a beginner. I was trying to make the classic 'guess the number' game and I want to add a function so that when i answer wrong in the first try, I want it to say 'try again' instead of 'guess a number'. I hope you can help, thanks.
FYI indentation should be 4 spaces per level.
guess_count = 0
guess_most = 3

while guess_count<guess_most:
    if guess_count > 0:
        answer = input('Guess again')
    else:
        answer=input('Guess a number ')
    guess_count+=1
    if str(answer)==str(winning_number):
        print('Correct!')
        break