-
Notifications
You must be signed in to change notification settings - Fork 0
/
Random Number.py
69 lines (61 loc) · 2.21 KB
/
Random Number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from os import system
from time import sleep
import random
# define cls command
def cls():
_ = system('cls')
# main loop
try:
while True:
while True:
cls()
print('Random Number Generator\n')
try:
#ask for min and max integer, filter negative numbers and strings
min = int(input('Minimum: '))
if(min >= 0):
try:
max = int(input('Maximum: '))
if(max >= 0):
if(min <= max):
break
else:
print("The minimum value is langer than the max value!")
sleep(1)
else:
print("Please enter a positive integer.")
sleep(1)
except ValueError:
print("That is not an integer.")
sleep(1)
else:
print("Please enter a positive integer")
sleep(1)
except ValueError:
print("That is not an integer.")
sleep(1)
# define random integer from min to max
rand_int = (random.randint(int(min),int(max)))
cut = 0
x = ""
cls()
# cut every digit from rand_int after third number and store amount of cut numbers
if(len(str(rand_int)) > 3):
cut = len(str(rand_int)) - 3
rand_int_cut = int(str(rand_int)[:-cut])
else:
rand_int_cut = rand_int
# insert random number from 1 to 9 for every cut number
for i in range(rand_int_cut):
x = ""
for not_used in range(cut):
x += str(random.randint(1, 9))
print(str(i) + str(x), end='\r')
sleep(0.01)
# print final value and pause
print(rand_int)
input("Press Enter to continue...")
# catch KeyboardInterrupt and print exit text
except KeyboardInterrupt:
cls()
print("\33[34mThsnks for using RndNmbrGen\33[0m")