我正试图在python中制作一个“pi实践”程序,如果正确的话,我希望用户的输入放在“3”旁边。
我有:
numbers = [1,4,1,5,9,2,6,5]
def sequence():
i = input("3.")
y = int(i)
if y == numbers[0]:
print ("Good job!")
#??????
numbers.pop(0)
sequence()
else:
print("nope")
sequence()
sequence()
因此,当提示时,如果用户输入1作为第一个数字,我希望下一个输入提示为3.1,所以用户必须输入4,依此类推。
提前谢谢你!-rt
发布于 2017-04-15 15:10:43
不需要递归,只需简单的while循环即可。通常情况下,利用全局变量并不是很好的做法:
def sequence():
numbers = [1,4,1,5,9,2,6,5]
prompt = '3.'
while numbers:
i = input(prompt)
y = int(i)
if y == numbers[0]:
print ("Good job!")
prompt += i
numbers.pop(0)
else:
print("nope")
sequence()
https://stackoverflow.com/questions/43427622
复制相似问题