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
What I tried
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
CodePudding user response:
You can the following a try, where it makes you keep trying until you say the last number in the solution:
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
CodePudding user response:
not sure if this is what you were asking for, but here is what i would do
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'
CodePudding user response:
You can use this.
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