Python Forum

Full Version: Two lines of code at the same time?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm making a small game I want the player to press A quickly. I print this and was thinking of a timer going up and when 'A' is pressed the timer will stop if it is fast enough then they'll pass.

Another idea was a timers set or a variable adds +1 and when at 10 they lose. But you can have simultaneous lines of code at a time?
You don't need to have simultaneous code. When the button is pressed, you just record how long it took them. Then you have a conditional (if statement) to see if the time was short enough for a pass, and then in the body of the conditional you can execute however many lines of code you want.

if time_taken < maximum_time:
   do_something()
   do_another_thing()