简体   繁体   中英

How do I make different things happen at different times in python

I am trying to make an alternative agc in python3, but i can't figure out how to make multiple things happen at different times (for example, thing A happens after 1 second and thing B happens after 2 seconds) the code I tried looks like this

if start_time < 9.9:
        print("Timer will wait for sometime before calling the function")
    else:
        print("Pitch and roll maneuver started.")
    if start_time < 23.325:
        print("Timer will wait for sometime before calling the function")
    else:
        print("Roll maneuver ended.")
    if start_time < 101.34:
        print("Timer will wait for sometime before calling the function")
    else:
        print("S-IC center engine cutoff command.")
    if end_time - start_time < 120.0:
        print("Timer will wait for sometime before calling the function") 
    else:
        print("Pitch maneuver ended.")

I took into consideration trying to make it so after 1 second thing A happens and thing A also sets a another timer for thing B to happen, but that would be a lot of def 's and I dont want to make the file so big that my computer crashes

you can use while loop and sleep

from time import sleep

start_time = 0
end_time = 11

while True:
    start_time += 1
    if start_time == 3:
        print("\nPitch and roll maneuver started.")
    elif start_time == 6:
        print("\nRoll maneuver ended.")
    elif start_time == 9:
        print("\nS-IC center engine cutoff command.")
    elif  start_time == end_time:
        print("\nPitch maneuver ended.")
        break
    else:
        print("Timer will wait for sometime before calling the function", end="\r")
    
    sleep(1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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