solution = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
enter number >1
enter number >1
enter number >2
enter number >3
enter number >5
enter number >8
enter number >3
Try again
我試過的
guess = int(input("Enter the next Fibonacci number >"))
solution = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
while guess not in solution or guess < 50:
guess = int(input("Enter the next Fibonacci number >"))
# Use if condition to compare
if guess not in solution[0:] and guess not in solution:
print("Try again")
break
uj5u.com熱心網友回復:
您可以嘗試以下方法,它會讓您繼續嘗試,直到您說出解決方案中的最后一個數字:
solution = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
i = 0
while i < len(solution):
guess = int(input("Enter the next Fibonacci number >"))
# Use if condition to compare
if guess != solution[i]:
print("Try again")
else:
i = 1
uj5u.com熱心網友回復:
不確定這是否是您要的,但這是我會做的
solved = 'FALSE'
while solved == 'FALSE':
solution = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
answers = []
while len(answers) < 10:
answers.append(int(input('Enter the next Fibonacci number >')))
if answers == solution:
print('correct')
solved = 'TRUE'
else:
print('try again')
solved = 'FALSE'
uj5u.com熱心網友回復:
你可以使用這個。
solution = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
guess_num = 1
while guess_num < 10:
guess = int(input("Enter the next Fibonacci number >"))
if guess != solution[guess_num-1]: print("Try again"); break
guess_num = 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/521247.html
標籤:Python列表if 语句