我在Windows 7上使用pycharm 3.5 到达第 19 行时我得到类型错误,不可排序的类型 Int((
Import random
guessTaken =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 guessTaken < 6:
print ('take a guess')
guess =input()
guess=int(guess)
guessTaken=guessTaken +1
If guess <number:. # this where the error occur!
print('your guess is too low')
If guess>number:
print('guess is too high')
If guess==number:
break
If guess==number:
guessTaken = str(guessTaken)
print('good job, ' + myName + ' you guess my number in ' + guessTaken +'guess')
If guess !=number:
number=str (number)
如何解决此问题以及看到的任何其他错误?不要使用手机观看格式化
在循环的底部,你奇怪地将number
转换为字符串。 您无法将其与整数进行比较。 只需从代码底部删除该比较和转换即可。