-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerating_examples2.py
229 lines (212 loc) · 7.99 KB
/
generating_examples2.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
from tkinter import *
import random
w=Tk()
w.title(" Генерируем примеры")
w.geometry('500x500')
operation = 0
nb = 0
def sms(list):
a = random.randint(1, 10)
b = random.randint(1, 10)
c = random.randint(1, 10)
d = random.randint(1, 10)
e = a + b
f = c + d
g = max(a, b) - min(a, b)
h = max(c, d) - min(c, d)
if f != 0 and e % f == 0:
k = e // f
str0 = "(" + str(a) + " + " + str(b) + ") : (" + str(c) + " + " + str(d) + ") = \n"
str1 = str(k) + "\n"
elif e != 0 and f % e == 0:
k = f // e
str0 = "(" + str(c) + " + " + str(d) + ") : (" + str(a) + " + " + str(b) + ") = \n"
str1 = str(k) + "\n"
elif g != 0 and f % g == 0:
k = f // g
str0 = "(" + str(c) + " + " + str(d) + ") : (" + str(max(a, b)) + " - " + str(min(a, b)) + ") = \n"
str1 = str(k) + "\n"
elif g != 0 and h % g == 0:
k = h // g
str0 = "(" + str(max(c, d)) + " - " + str(min(c, d)) + ") : (" + str(max(a, b)) + " - " + str(min(a, b)) + ") = \n"
str1 = str(k) + "\n"
else:
k = g * h
str0 = "(" + str(max(a, b)) + " - " + str(min(a, b)) + ") * (" + str(max(c, d)) + " - " + str(min(c, d)) + ") = \n"
str1 = str(k) + "\n"
list.append((str0, str1))
def mms(list):
a = random.randint(1, 10)
b = random.randint(1, 10)
c = random.randint(1, 10)
d = random.randint(1, 10)
if a % b == 0:
k = a // b * c + d
str0 = str(a) + " : " + str(b) + " * " + str(c) + " + " + str(d) + " = \n"
str1 = str(k) + "\n"
elif a * b % c == 0:
k = a * b // c + d
str0 = str(a) + " * " + str(b) + " : " + str(c) + " + " + str(d) + " = \n"
str1 = str(k) + "\n"
elif a * b * c % d == 0:
k = a * b * c // d
str0 = str(a) + " * " + str(b) + " * " + str(c) + " : " + str(d) + " = \n"
str1 = str(k) + "\n"
elif (a + b) % c == 0:
k = (a + b) / c + d
str0 = "(" + str(a) + " + " + str(b) + ") : " + str(c) + " + " + str(d) + " = \n"
str1 = str(k) + "\n"
elif (a + b + c) % d == 0:
k = (a + b + c) / d
str0 = "(" + str(a) + " + " + str(b) + " + " + str(c) + ") : " + str(d) + " = \n"
str1 = str(k) + "\n"
else:
k = a * b * c + d
str0 = str(a) + " * " + str(b) + " * " + str(c) + " + " + str(d) + " = \n"
str1 = str(k) + "\n"
list.append((str0, str1))
def msm(list):
a = random.randint(1, 10)
b = random.randint(1, 10)
c = random.randint(1, 10)
d = random.randint(1, 10)
e = max(b, c) - min(b, c)
if a % (b + c) == 0:
k = a // (b + c) * d
str0 = str(a) + " : (" + str(b) + " + " + str(c) + ") * " + str(d) + " = \n"
str1 = str(k) + "\n"
elif e != 0 and a % e == 0:
k = a // e * d
str0 = str(a) + " : (" + str(max(b, c)) + " - " + str(min(b, c)) + ") * " + str(d) + " = \n"
str1 = str(k) + "\n"
elif a * (b + c) % d == 0:
k = a * (b + c) // d
str0 = str(a) + " * (" + str(b) + " + " + str(c) + ") : " + str(d) + " = \n"
str1 = str(k) + "\n"
elif a * e % d == 0:
k = a * e / d
str0 = str(a) + " * (" + str(max(b, c)) + " - " + str(min(b, c)) + ") : " + str(d) + " = \n"
str1 = str(k) + "\n"
else:
k = a * (b + c) * d
str0 = str(a) + " * (" + str(b) + " + " + str(c) + ") * " + str(d) + " = \n"
str1 = str(k) + "\n"
list.append((str0, str1))
def add(f, a, b, f1, i):
global nb
c = a + b
f.write(str(nb + i + 1) + ") " + str(a) + " + " + str(b) + " = \n")
f1.write(str(nb + i + 1) + ". " + str(c) + "\n")
def sub(f, a, b, f1, i):
global nb
c = a + b
f.write(str(nb + i + 1) + ") " + str(c) + " - " + str(b) + " = \n")
f1.write(str(nb + i + 1) + ". " + str(a) + "\n")
def mul(f, a, b, f1, i):
global nb
c = a * b
f.write(str(nb + i + 1) + ") " + str(a) + " * " + str(b) + " = \n")
f1.write(str(nb + i + 1) + ". " + str(c) + "\n")
def div(f, a, b, f1, i):
global nb
c = a * b
f.write(str(nb + i + 1) + ") " + str(c) + " : " + str(b) + " = \n")
f1.write(str(nb + i + 1) + ". " + str(a) + "\n")
def execute_all_actions(nb_ex):
global nb
list = []
f = open('action.txt', 'a')
f1 = open('answers.txt', 'a')
n = nb_ex // 3
for i in range(n):
sms(list)
mms(list)
msm(list)
random.shuffle(list)
i = nb + 1
for j in list:
f.write(str(i) + ") " + j[0])
f1.write(str(i) + ". " + j[1])
i += 1
nb += n * 3
f.close()
def execute_one_action(op, nb_ex, first, second):
global nb
f = open('action.txt', 'a')
f1 = open('answers.txt', 'a')
if op == 4:
first -= second
a = 10 ** first
b = 10 ** second
for i in range(nb_ex):
ran_a = random.randint(1, (a - 1))
ran_b = random.randint(1, (b - 1))
if op == 1:
add(f, ran_a, ran_b, f1, i);
elif op == 2:
sub(f, ran_a, ran_b, f1, i);
elif op == 3:
mul(f, ran_a, ran_b, f1, i);
elif op == 4:
div(f, ran_a, ran_b, f1, i);
nb += nb_ex
f.close()
def radio():
global operation
operation = var.get()
def clik():
global operation
first_component = 0
second_component = 0
namber_of_examples = 0
first_component = vvod.get()
second_component = vvod1.get()
namber_of_examples = vvod2.get()
try:
if operation == 0:
execute_all_actions(int(namber_of_examples))
else:
execute_one_action(operation, int(namber_of_examples), int(first_component), int(second_component))
txt_del = " Примеры сгенерированы, \n находятся в файле action.txt \n \
текущей директории, \n ответы в файле answers.txt"
txt_ex.configure(text=txt_del, fg = 'green')
except:
exc = " Пожалуйста, проверьте, \n что во все поля введены целые числа.\n \
Не рекомендуется указывать \n количество разрядов более 6"
txt_ex.configure(text=exc, fg = 'red' )
#creating the main window
var = IntVar()
var.set(0)
rad0 = Radiobutton(w, text = "Примеры на все действия", variable = var,
value = 0, command = radio)
rad1 = Radiobutton(w, text = "Сложение", variable = var, value = 1, command = radio )
rad2 = Radiobutton(w, text = "Вычитание", variable = var, value = 2,command = radio )
rad3 = Radiobutton(w, text = "Умножение", variable = var, value = 3, command = radio)
rad4 = Radiobutton(w, text = "Деление", variable = var, value = 4, command = radio)
rad0.grid(column = 0, row = 0)
rad1.grid(column = 0, row = 1)
rad2.grid(column = 0, row = 2)
rad3.grid(column = 0, row = 3)
rad4.grid(column = 0, row = 4)
txt = Label(w, text = "Количество разрядов в первом компоненте?",
font = ("Arial Bold", 10))
txt.grid(column = 0, row = 6)
vvod = Entry(w, width = 10)
vvod.grid(column = 1,row = 6)
vvod.focus()
txt1 = Label(w, text = "Количество разрядов во втором компоненте?",
font = ("Arial Bold", 10))
txt1.grid(column = 0, row = 7)
vvod1 = Entry(w, width = 10)
vvod1.grid(column = 1, row = 7)
vvod1.focus()
txt2 = Label(w, text = "Количество примеров:", font = ("Arial Bold", 10))
txt2.grid(column = 0, row = 8)
vvod2 = Entry(w, width = 10)
vvod2.grid(column = 1, row = 8)
vvod2.focus()
txt_ex = Label(w, text = "", font = ("Arial Bold", 10), fg = 'red', width = 40, height = 8, justify = 'left')
txt_ex.grid(column = 0, row = 11)
kn=Button(w,text="Сгенерировать", command=clik)
kn.grid(column=1,row=10)
w.mainloop()