为什么 Python 在未注释且另一行不存在时不喜欢已注释的打印行?
# This is a guess the number game
import random
guessesTaken = 0
myName = input('Hi there! What is your name?')
number = random.randint(1, 20)
print('Well ' + myName + ' I am thinking of a number between 1 and 20')
while guessesTaken < 6:
guess = int(input('Try and guess what it is!')) # There are 4 spaces in front of print.
# guess = int(input ())
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low') # There are 8 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 ' + number + ' in ' + guessesTaken + ' guesses!')
print('Good Job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('I am sorry. The number I was thinking of was ' + number + ' Thanks for playing, though.')
input('\n\nPress Enter to exit')