This Python script will emulate number station stream. You can use it as screensaver or just for experiments.
Random module is for, well, randomness, and time module is for pause between generations.
import random, time
While True is needed so this random number generator will work constantly.
Variables rn from 1 to 4 will hold random number from 1000 to 9999.
rn_1 = random.randint(1000, 9999)
rn_2 = random.randint(1000, 9999)
rn_3 = random.randint(1000, 9999)
rn_4 = random.randint(1000, 9999)
After that, you can just print variables, or, of you need more numbers just multiply existing variables with some constant as 0.8 or something.
print(rn_1, '\t', int(rn_1*0.8), '\t',
int(rn_2), '\t',int(rn_2*0.8), '\t',
int(rn_3), '\t',int(rn_3*0.8), '\t',
int(rn_4), '\t',int(rn_4*0.8), '\t')
time.sleep(1)
You can have as menu random numbers as you like :)
Full Script:
import random, time
while True:
rn_1 = random.randint(1000, 9999)
rn_2 = random.randint(1000, 9999)
rn_3 = random.randint(1000, 9999)
rn_4 = random.randint(1000, 9999)
print(rn_1, '\t', int(rn_1*0.8), '\t',
int(rn_2), '\t',int(rn_2*0.8), '\t',
int(rn_3), '\t',int(rn_3*0.8), '\t',
int(rn_4), '\t',int(rn_4*0.8), '\t')
time.sleep(1)
Learn More:
Free Python Programming Course
Python Examples
Python How To
Python Modules
No comments:
Post a Comment