-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice_randomisation.py
70 lines (56 loc) · 2.4 KB
/
practice_randomisation.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
70
# This programm is for practice of randomisation code.
import random
print("Welcome to lotto predictor!")
# Ask number range.
number_range = input("Please the largest number in your country's lotto system.\n")
# Check if input is number.
while not number_range.isdigit():
number_range = input("Please input number only\n")
# Ask how many picks user wants
picks = input("How many picks do you want?\n")
# Check if input is number.
while not number_range.isdigit():
picks = input("Please input number only\n")
# Randomise 6 numbers.
random_int1 = random.randint(1, int(number_range))
random_int2 = random.randint(1, int(number_range))
random_int3 = random.randint(1, int(number_range))
random_int4 = random.randint(1, int(number_range))
random_int5 = random.randint(1, int(number_range))
random_int6 = random.randint(1, int(number_range))
# Avoid duplicated numbers among 6 numbers above.
for i in range(0, int(picks)):
random_int1 = random.randint(1, int(number_range))
random_int2 = random.randint(1, int(number_range))
random_int3 = random.randint(1, int(number_range))
random_int4 = random.randint(1, int(number_range))
random_int5 = random.randint(1, int(number_range))
random_int6 = random.randint(1, int(number_range))
while (
(random_int1 == random_int2)
or (random_int1 == random_int3)
or (random_int1 == random_int4)
or (random_int1 == random_int5)
or (random_int1 == random_int6)
or (random_int2 == random_int3)
or (random_int2 == random_int4)
or (random_int2 == random_int5)
or (random_int2 == random_int6)
or (random_int3 == random_int4)
or (random_int3 == random_int5)
or (random_int3 == random_int6)
or (random_int4 == random_int5)
or (random_int4 == random_int6)
or (random_int5 == random_int6)
):
random_int1 = random.randint(1, int(number_range))
random_int2 = random.randint(1, int(number_range))
random_int3 = random.randint(1, int(number_range))
random_int4 = random.randint(1, int(number_range))
random_int5 = random.randint(1, int(number_range))
random_int6 = random.randint(1, int(number_range))
print(random_int1, random_int2, random_int3, random_int4, random_int5, random_int6)
# Print result.
print("Good Luck!")
# I will learn set function to simplify codes.
# I will learn how to organize numbers in order.