我是Numguess的锻炼者。在python 3.7.4中,它显示“ Type错误:在'str'和'int'的实例之间不支持'<'”
import random
secret = random.randint(1,99)
guess = 0
tries = 0
print ("AHOY! I'm the Dread pirate Roberts, and I have a secret!")
print ("It is a number from 1 to 99. I'll give you 6 tires.")
while guess != secret and tries < 6:
guess = input ("What's your guess?")
if guess < secret:
print ("Too low, ye scurvy dog!")
elif guess > secret:
print ("Too high, landlubber!")
tries = tries + 1
if guess == secret:
print ("Avast! you got it! Found my secret, ye did!")
else:
print ("No more guesses! Better luck next time, matey!")
print ("The secret number was", secret)
============== RESTART: /Users/mac/Documents/python/Numguess.py ==============
AHOY! I'm the Dread pirate Roberts, and I have a secret!
It is a number from 1 to 99. I'll give you 6 tires.
What's your guess?40
Traceback (most recent call last):
File "/Users/mac/Documents/python/Numguess.py", line 9, in <module>
if guess < secret:
TypeError: '<' not supported between instances of 'str' and 'int'