Question

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?

No correct solution

OTHER TIPS

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)
from time import sleep
for x in range(0,10):
    print (random.randint(0,100))
    sleep(3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top