On 03/10/17 22:49, steve.lett...@gmail.com wrote: > That is guessesTaken. It reads 0 when it should be a larger number.
What makes you think so? You never increase it from its initial value so, quite correctly it stays at zero. > I am a beginner having another try to get it! Remember the computer just does what you tell it and nothing more. It has no idea what you are trying to do so it needs you to tell it exactly what to do. Every single thing. And in this case you need to add 1 to guessesTaken each time the user makes a guess. > # This is a Guess the Number game. > import random > > guessesTaken = 0 > > print('Hello! What is your name?') > myName = input() > > number = random.randint(1, 20) > print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') > > for i in range(6): > print('Take a guess.') # Four spaces in front of "print" > guess = input() > guess = int(guess) you probably should have a line here like: guesesTaken += 1 > if guess < number: > print('Your guess is too low.') # Eight spaces in front of "print" > > if guess > number: > print('Your guess is too high.') > > if guess == number: > break > > if guess == number: > guessesTaken = str(guessesTaken) > print('Good job, ' + myName + '! You guessed my number in ' + > guessesTaken + ' guesses!') > > if guess != number: > number = str(number) > print('Nope. The number I was thinking of was ' + number + '.') -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor