我有一个代码块,使用户输入斐波那契数列。代码块:
numb_list = [0, 1, 2, 3, 5, 8, 13, 21, 34, 55]
numb = int(input('Enter the next Fibonacci number >'))
while numb in numb_list and numb <= 50:
numb = int(input('Enter the next Fibonacci number >'))
if numb in numb_list:
print('Well done')
else:
print('Try again')
我要求用户输入这些数字。当用户输入超过50或输入所有正确的数字时,程序会给出输出“做得好”。如果用户输入错误,程序将输出“重试”。这是完美的工作,但我将如何使用户输入按照这个特定的顺序跟随这个列表,如果不是按照这个顺序,程序输出“重试”。
这是电流输出:
Enter the next Fibonacci number >1
Enter the next Fibonacci number >1
Enter the next Fibonacci number >2
Enter the next Fibonacci number >3
Enter the next Fibonacci number >8
Enter the next Fibonacci number >3
Enter the next Fibonacci number >
这是我想要实现的输出:
Enter the next Fibonacci number >1
Enter the next Fibonacci number >1
Enter the next Fibonacci number >2
Enter the next Fibonacci number >3
Enter the next Fibonacci number >8
Enter the next Fibonacci number >3
Try again
不幸的是,我在实现此输出时遇到问题。有人能帮助我吗?
万千封印
慕尼黑8549860
有只小跳蛙
随时随地看视频慕课网APP
相关分类