import randomsecret = random.randint (1,99)guess = 0tries = 0print ("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 tries. ")while guess != secret and tries < 6: guess = input ("What's yer guess? ") if guess < secret: print ("Too low, ye scurvy dog") elif guess > secret: print ("Too high, landrubber!") tries = tries + 1if guess == secret: print ("Avast! Ye got it! Found my secret, ye did!")else: print ("No more guesses! Better luck next time, matey!") print ("The secret number was", secret)我不断收到此错误:如果猜测 类型错误:无法排序的类型:str() 最佳答案 guess = input ("What's yer guess? ")调用 input 会返回一个 string ,而不是 int 。当您使用 guess 比较 < 时,您需要一个 int 来比较数值。尝试按照以下方式做一些事情:try: guess = int(input("What's yer guess? "))except ValueError: # Handle bad input关于python - 这个 Python 游戏代码有什么问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3514154/
10-12 21:56