Write a Python program to print a string ten times, delay two seconds


The program starts by importing the time module from the Python Standard Library. A variable x is created and set to 0. This variable will be used in a while loop to control the number of times the loop is executed. The while loop starts, and will continue to execute as long as the value of x is less than 10. On each iteration of the loop, the following actions are performed:

  • The string "Tutor Joe's" is printed to the console using the print function.
  • The time.sleep function is called with an argument of 2 seconds, causing the program to pause for 2 seconds before continuing.
  • The value of x is incremented by 1, so that the condition of the while loop can be re-evaluated.

The loop will repeat these actions until the value of x is no longer less than 10, at which point the loop will terminate and the program will end. The result of this program is that the string "Tutor Joe's" will be printed to the console 10 times, with a 2-second pause between each print.

Source Code

import time 
x=0
while x<10:
    print("Tutor Joe's")
    time.sleep(2)
    x=x+1

Output

Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's
Tutor Joe's

Example Programs