+ 1
executing program based on time related actions
Hi, Can a python program run based on a series of staggered timing steps? As i understand the program all actions all at once. So i woild like to have a program to say at 3 sec into program move object 1 then after 5 secs move another etc. Thank you in advanced.
4 Respuestas
+ 2
If you are working outside of SoloLearn's emulator, there are two valid ways to do this:
1. You can use the sleep function from the time module:
import time
print("something")
time.sleep(2.5) # pauses for 2.5 seconds
print("something")
But this does not seem to work in the emulator, as it does evaluates the whole program first and then gives you the output all at once.
2. You could use the input function to ask for user input before moving to the next step:
print("something")
wait = input("PRESS ENTER TO CONTINUE.")
print("something")
This is better in cases when the time to pause the code depends on the user (i.e. if they have to read some text). However, it does not work in the emulator either, because it asks for input at the start of the code, rather than doing it at tge point where it is defined.
Basically, it can be done, but not in the environment that SoloLearn has provided us with.
+ 1
time.sleep() would be best for your case, but it does not work in SoloLearn's emulator.
0
Thanks for the prompt response.
I would prefer not to have user input as what I am trying to produce is a short animation.
0
Your assistance is much appreciated.