0
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.
randoz is a function i made, non relevent.

  • 1
    Well, you either want user input, or you don't. Having both does not seem to be a solution – omu_negru Aug 18 '17 at 09:31
  • 1
    @omu_negru You can have a _timeout_ solution as described [here](https://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python) or [here](https://stackoverflow.com/questions/15528939/python-3-timed-input) – Ma0 Aug 18 '17 at 09:32
  • Possible duplicate of [Python 3 Timed Input](https://stackoverflow.com/questions/15528939/python-3-timed-input) – Ma0 Aug 18 '17 at 09:32

1 Answers1

0

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

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
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65