我花了 1.5 个小时的大部分时间在这件事上工作,但我就是无法让它工作。在它开始抛出这些奇怪的语法错误之前,它会继续说“猜低,再试一次”。我遇到的这些错误甚至没有在 shell 中运行。
这是代码:
import random
gend = random.randint(1,100) #make random number
def compare(gend,guess): #start function
guessnum = 0 #set guessnumber to zero for later printing
if gend < guess: #compare gend number against guessed number
int(raw_input("Too high. Try again. ")) #request another number for user
guessnum = guessnum + 1 #add 1 to guessnumber, for later printing
elif gend > guess: #compare gend number against guessed number
int(raw_input("Too low. Try again. "))#request another number for user
guessnum = guessnum + 1 #compare gend number against guessed number
elif gend == guess: #if guessed number=gend, do this
keepalive = 'much spook' #stop the while loop
print "Congratulations! You got it in %d guess." % (guessnum)#print da amount of guesses
keepalive = 'rekt' #keepalive substitute
print 'Time to play a guessing game' #no exp needed
guess = int(raw_input("Enter a number between 1 and 100: ") #start off the game
while keepalive == 'rekt': #while loop that does all the work
compare(gend,guess) #funcion werk
raw_input("Any key to exit") #keep console open so it doesnt autoclose -.-
我还要感谢你们的帮助,可以说是大多数语言的最佳学习资源。