Reputation: 11
I am trying to create a program on Python which shows a random number every 3 seconds for 30 seconds. I know how to do it the long way like this:
import random
print (random.randint(0,100))
from time import sleep
sleep(3) # Time in seconds
I did this ten times. Is there any way to make this process shorter?
Upvotes: 1
Views: 905
Reputation: 37033
Use looping, which is designed for just such requirements:
import random
import time
for i in range(10):
print(random.randint(0, 100))
time.sleep(3)
Upvotes: 1
Reputation: 4940
from time import sleep
for x in range(0,10):
print (random.randint(0,100))
sleep(3)
Upvotes: 0