Python制作数字猜谜游戏

时间:2016-05-20 12:08:56

标签: python

我的代码:

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.这个错误 - 回溯(最近一次呼叫最后一次):

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

2.需要修复它并显示你得到了多少猜测答案。

1 个答案:

答案 0 :(得分:1)

问题在于这一行:

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

print会返回None,这样您的变量就会得到这个值。删除作业,它将起作用:

print('Thats a guess gone.')