[Tutor] (no subject)

steve.lett777 at gmail.com steve.lett777 at gmail.com
Tue Oct 3 17:49:53 EDT 2017


Can u please tell me why this program does not work in line 28? That is guessesTaken. It reads 0 when it should be a larger number.

I am a beginner having another try to get it!

Thank you, Steve

PS. Python 3.5.1 and Win10

# 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)

    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 + '.')


Sent from Mail for Windows 10

From: tutor-request at python.org
Sent: Tuesday, 3 October 2017 3:02 AM
To: tutor at python.org
Subject: Tutor Digest, Vol 164, Issue 5





---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


More information about the Tutor mailing list