Python Forum
Script that alternates between 2 text messages - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Script that alternates between 2 text messages (/thread-41278.html)



Script that alternates between 2 text messages - DiscoMatic - Dec-12-2023

Hello,

I am completely new tho Python, but i would like to program a script that alternates between 2 text messages.

first is displays "Drive" and then 2sec later "Through", then again 2seconds later "Drive", and so on...

Can somebody help me please?


RE: Script that alternates between 2 text messages - buran - Dec-12-2023

from itertools import cycle
from time import sleep

for msg in cycle(['Drive', 'Through']):
    print(msg)
    sleep(2)