简体   繁体   English

Python-如何在绝对没有输入的情况下继续循环,包括输入键

[英]Python - how to continue a loop with absolutely no input, including enter key stroke

ayy = 0

while True:        
    ayy = ayy + 1                                 

    print(Randoz(a,b,c,d))           
    if ayy % 3 == 0:                  

    omg = input('Do you wish to stop the loop?, if yes type yes, if not, type no')   

    if omg == 'yes':                           
     break     

    if omg == '':
    ayy = ayy                   

i am trying to make a loop that every 3 laps stops and asks the user if he wants to break, and to have an option to not do anything and continue the loop, i cant seem to figure out how to continue it without the user doing anything, i need to press enter for it to do another loop. 我正在尝试制作一个每3圈停下来的循环,并询问用户是否要中断,并可以选择不做任何事情并继续循环,我似乎无法弄清楚如何在用户不做的情况下继续循环任何事情,我都需要按Enter以便进行另一个循环。
randoz is a function i made, non relevent. randoz是我创建的函数,无关紧要。

You could use the following code to start a loop that will run forever and only quit when the user adds 'y' or 'Y' when prompted for input on each third iteration 您可以使用以下代码启动一个循环,该循环将永远运行,并且仅当用户在每次第三次迭代中提示输入时,才在用户添加'y''Y'时退出

import itertools
for i in itertools.count(1):
     print(Randoz(a,b,c,d))
     if i % 3 == 0:
         quit = input('Do you want to quit? y/n')

         if quit.lower() == 'y':
             break

Example output with iterations being printed: 输出示例并打印迭代:

1
2
3
Do you want to quit? y/n
4
5
6
Do you want to quit? y/n
7
8
9
Do you want to quit? y/n
10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM