print("Guess the hidden number between 1 and 100")
guess = int(input("Enter your guess:\n")
if guess==67
print("Correct Well Done")
elif guess<67
print("Your guess is too low. Try again.")
else guess>67
print("Your guess is too high. Try again.")
然后我想让它在每次用户输入答案时重复此操作,然后当他们最终正确时,它会停止。
答案 0 :(得分:1)
可以在代码中添加一个简单的while循环。但请注意,对猜测值进行硬编码并不会产生最易维护的代码。
-1
您可能希望实施&#34;找到&#34;如果找到变量并突破循环
guess = 0
while guess != 67:
print("Guess the hidden number between 1 and 100")
guess = int(input("Enter your guess:\n")
if guess==67:
print("Correct Well Done")
elif guess<67:
print("Your guess is too low. Try again.")
else guess>67:
print("Your guess is too high. Try again.")
答案 1 :(得分:0)
试试这个。添加了冒号&#34;:&#34;。您的代码无效的原因是book_1 = "A Wrinkle in Time"
book_2 = "A Brief History of Time"
和if
之后缺少的冒号。
elif