循环输入直到满足参数或用户输入

时间:2018-12-03 22:01:22

标签: python user-interface while-loop user-input

我希望我的程序在继续运行之前等待10秒钟,或者通过用户输入来中断循环

try:
    while True:
        afkseconds = 0
        time.sleep(1)
        afkseconds +=1
    if afkseconds == 10:
            Timer()
except KeyboardInterrupt:
    pass

newTaskIO = input('Y/N: ')
newTaskIO = newTaskIO.lower()

if newTaskIO == 'y':
    taskName = input('Enter the name of the task: ')
    taskDescription = input('Enter a brief description, or press enter to continue: ')

程序进入while循环,在“ afksecond”变量中增加一秒钟。这个想法是,一旦afksecond变量= 10,循环就会中断并执行指定的功能。

或者用户输入“ y”或“ n”来中断循环并继续进行程序的下一阶段。我无法弄清楚使它起作用的逻辑。请告诫

0 个答案:

没有答案