代码运行正常,直到它询问您是否要继续播放。截至目前,无论您输入什么,它都会再次通过提示。如果你输入任何以y开头的东西,我需要它再次运行,如果输入任何其他东西,我需要打破
while(str(guess) == str(random_num)):
if(int(num_sum) <= int(1)):
print("You got it right in 1 guess!")
again = str(input("Would you like to play again? "))
print()
return prompt()
elif(int(num_sum) > int(1)):
print("you got it right in " + str(num_sum) + " guesses! ")
again = str(input("Would you like to play again? "))
return prompt()
if(str(again.startswith)("y") or ("Y")): #am I using the "startswith" feature wrong?
print()
return prompt()
else:
print("Overall Results")
break
答案 0 :(得分:-1)
def prompt():
constant_1 = 1
constant_2 = 100
random_num = (randint(constant_1, constant_2))
im_thinking = ("I'm thinking of a number between" +
(" ") + str(constant_1) + (" ") + ("and") + (" ") + str(constant_2) + ("..."))
print(im_thinking)
print(random_num)
guess = int(input("Your guess? "))
num_sum = 1
while((str(guess) != str(random_num))):
num_sum = num_sum + 1
if (str(guess) > str(random_num)):
print("It's lower.")
guess = int(input("Your guess? "))
elif (str(guess) < str(random_num)):
print("It's higher.")
guess = int(input("Your guess? "))
else:
guess = False