0

I am trying to build a simple game where the user is asked to press 'P' to start, and it will start generating different patterns until the user presses 'S'. Obviously what I have doesn't work, but I am not sure what to do at this point.

while ans == 'p' or ans == 'P':

    function1()
    function2()
    function3()

    if ans == 's' or ans == 'S':
        break

I have seen solutions where keyboard.is_pressed() is used but is there a way to do this without using any pre-defined function?

Thanks!

fl1332113
  • 13
  • 2
  • you can get the user input with just `ans = input("press P or S: ")`, so you wont need you `if` statement at the end – Rodrigo Rodrigues Apr 23 '22 at 01:13
  • This is an assignment and unfortunately, I have to follow the instructions step by step. So basically, it starts off with a pattern where the user is asked to press P to play, after they press P, the functions will generate new patterns according to the initial pattern, and then make a copy and display the new pattern. It will keep on generating new patterns until the user presses S (stop), and this is where I am stuck. – fl1332113 Apr 23 '22 at 01:20
  • 1
    This can be accomplished in many ways, but your "without using any pre-defined function" is too broad to provide you with any assistance. What have you tried so far? – blarg Apr 23 '22 at 01:42
  • @blarg I wasn't able to come up with other methods besides the one I posted, which completely stops other patterns from being generated unless I press P again to generate another one and it stops again. I did install the keyboard module and while it works, I was wondering if there is another method that doesn't require me to have to install anything. – fl1332113 Apr 23 '22 at 05:46
  • I think that you need a non-blocking input. Take a look at this question: https://stackoverflow.com/q/2408560/542196 You can choose from multiple solutions ranging from different libraries through threading to `curses`. – radekholy24 Apr 23 '22 at 19:20

0 Answers0