-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchits_generator.py
120 lines (107 loc) · 4.32 KB
/
chits_generator.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# python chits_generator.py
import random
def chit():
num={}
num['num10'] =[i for i in range(1,11)]
num['num20'] =[i for i in range(11,21)]
num['num30'] =[i for i in range(21,31)]
num['num40'] =[i for i in range(31,41)]
num['num50'] =[i for i in range(41,51)]
num['num60'] =[i for i in range(51,61)]
num['num70'] =[i for i in range(61,71)]
num['num80'] =[i for i in range(71,81)]
num['num90'] =[i for i in range(81,91)]
results ={}
# target => select 15 numbers
for key,value in zip(num.keys(),num.values()):
# 1. select each one from 10 steps (9 done,6 left)
results[key] = [num[key].pop(num[key].index(random.choice(value)))]
# 2. while loop to run the program till 15 number will selected and not 3 more then 10 gap
while len([j for i in results.values() for j in i]) < 15:
# 1. randomly choice from list of the num list
key = random.choice(list(num.keys()))
# 2. check if there is less then 3 else continue
if len(results[key]) < 3 :
# randomly choice element and add to the results list and pop from num list
results[key].append(num[key].pop(num[key].index(random.choice(num[key]))))
else:
continue
else :
# no break else to sort the results lists at last
[results[result].sort() for result in results]
### arranging in the order of requirement ####
chit = [[' ',' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' ',' ']]
row_c1,row_c2 = [],[]
# 1. first check if any list have 3 element if true append in chit
for index,value in enumerate(results.values()):
if len(value) == 3 :
key = list(results.keys())[index]
row_c1.append(key)
row_c2.append(key)
for i,item in enumerate(value) :
chit[i][index] = str(item)
else :
# clearing all the done list
for ele in row_c1:
del results[ele]
# complete the first row
row = 0 # current row
for i in range(5-len(row_c1)):
# loop lill new key doesnot found
while True:
key = random.choice(list(results.keys()))
if key not in row_c1 : break
index = int(list(num.keys()).index(key))
value = results[key].pop(0)
row_c1.append(key)
chit[row][index] = str(value)
if results[key] == []:
del results[key]
# 2. check if any list have 2 element if true append in chit
for key,value in zip(results.keys(),results.values()) :
if len(value) == 2 :
row_c2.append(key)
index = list(num.keys()).index(key)
for i,item in enumerate(value,1) :
chit[i][index] = str(item)
else:
# clearing all the done list
for ele in row_c2:
try:
del results[ele]
except:
pass
# complete the second row
row = 1 # current row
for i in range(5-len(row_c2)):
# loop till new key doesnot found
while True:
key = random.choice(list(results.keys()))
if key not in row_c2 : break
index = int(list(num.keys()).index(key))
value = results[key].pop(0)
row_c1.append(key)
chit[row][index] = str(value)
if results[key] == []:
del results[key]
# complete the third row
for key,value in zip(results.keys(),results.values()):
chit[2][list(num.keys()).index(key)] = str(value[0])
return chit
def save_chits_in_file(how_many_chits=1,number_to_start=1):
with open("Tambola tickets.txt",'w') as file:
for i,nu in enumerate([x for x in range(how_many_chits)],number_to_start):
line1,line2,line3 = chit()
file.writelines(f' lottery ticket by Rishi - {i}'+'\n')
file.writelines(str(line1)+'\n')
file.writelines(str(line2)+'\n')
file.writelines(str(line3)+'\n')
file.writelines('\n')
# re = 5
re=int(input('Enter the number of chits require :'))
if re != 0 :
save_chits_in_file(how_many_chits=re)
else :
print('no chits saved')