這是我的代碼:我已經做了猜測的數字遊戲,但我每次運行它,並鍵入一些時間這個崩潰
#This is a guess the number game
import random
print('Hello what is your name')
name = input()
secretNumber = random.randint(1, 20)
print('Well ' + name + ' I am thinking of a number between 1 and 20. You have 6 guesses')
#Ask the player to guess 6 times.
for guessTaken in range(1, 7):
try:
print('Take a guess')
guess = int(input())
except ValueError:
print('That is not a number')
guess = int(input())
guess = str(input())
if guess < secretNumber:
print('Your guess is to low.')
elif guess > secretNumber:
print('Your gues s is to high.')
else:
break # This condition is the correct guess!
if guess == secretNumber:
print('Good job ' + name + '. You guessed my number!')
print('It was ' + str(secretNumber))
print('and you guessed it in ' + str(guessTaken) + ' guesses')
else:
print('Nope. The number I was thinking of was ' + str(secretNumber))
當過我運行它,並鍵入一些這樣出現:猜= INT(輸入()) ValueError異常:無效的字面INT()基數爲10: ''
在guess = int(input())之後,你會怎麼想'guess = str(input())'? –