beginner27_
beginner27_

Reputation: 1

Execute 2 tasks for a specific amount of time (Python)

I need to print out "Hello World" for 3.5 seconds.

import time

t_end = time.time() + 3.5
while time.time() < t_end:
    print("Hello World")  

After that time, another text should be printed out automatically for 3.5 seconds. How can I make an infinite loop here?

Upvotes: 0

Views: 39

Answers (1)

Phade
Phade

Reputation: 11

You mean something like this?

import time

while True:
    print("Hello world!")
    time.sleep(3.5)
    print("Hello again!")
    time.sleep(3.5)

Upvotes: 1

Related Questions