Python制作数字猜谜游戏

Python making a number guessing game

我的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.')

while guessesTaken < 5:
     print('Take a guess.')

     guess = input()
     guess = int(guess)
     guessesTaken = guessesTaken + 1
     guessesTaken = print('Thats a guess gone.')


     if guess < number:
         print('Your guess is too low.')


     if guess > number:
         print('Your guess is too high.')

     if guess == number:
          print('You won at life!')
          break

     if guess == number:
        print('idk, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
print('Again? Again.')

需要帮助:

1.这个错误 - 回溯(最近一次调用最后一次):

1
2
3
  File"\\wbs-fs01\2013$\13CDyke\Guessing game.py", line 12, in <module>
    while guessesTaken < 5:
TypeError: unorderable types: NoneType() < int()

2.需要修复它并显示你得到答案的猜测数量。


问题是这一行:

1
guessesTaken = print('Thats a guess gone.')

print返回None,这是变量得到的值。 删除任务,它将工作:

1
print('Thats a guess gone.')