-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
241 lines (178 loc) · 7.45 KB
/
main.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
230
231
232
233
234
235
236
237
238
239
240
241
import re
import protips as pp
from core import utils
import os
from tkinter import *
from tkinter.font import BOLD
from tkinter import messagebox
from playsound import playsound
import shlex,subprocess
prtip=''
def main():
eg=utils.dataclass()
if eg.first:
pass
def checker(inp):
try:
exec(inp)
except Exception as e:
lbl.config(text="Invalid python syntax!\n\tTry again!")
playsound('sounds/gameover.wav')
return
global prtip
prtip=''
s=''
if eg.eggs['print'] and 'print' in inp:
s='Now, see how `print` is done in c++ : \n'
f = open("files/print.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to program with two `cout` statements in the right side c++ editor'
f.close()
prtip+=pp.prot["print"]
playsound('sounds/coin.mp3')
lbl.config(text=s)
eg.eggs['print']=0
eg.dict_file()
if eg.eggs['if'] and 'if' in inp:
s='Now, see how `if` is used in c++ : \n'
f = open("files/if.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to have a condition to check if a number is negative with `cout` statements'
prtip+=pp.prot["if"]
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['if']=0
eg.dict_file()
if eg.eggs['elif'] and 'elif' in inp:
s='Now, see how `else if` is used in c++ : \n'
f = open("files/elif.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to check weather a number is higher than 100 or higher than 10 `cout` statements'
prtip+=pp.prot["elif"]
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['elif']=0
eg.dict_file()
if eg.eggs['else'] and'else' in inp:
s='Now, see how `else` used in c++ : \n'
f = open("files/else.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to check if a number is divisible by 2 `cout` statements'
prtip=pp.prot["else"]
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['else']=0
eg.dict_file()
if eg.eggs['for'] and 'for' in inp:
s='Now, see how `for loop` is done in c++ : \n'
f = open("files/for.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to use a loop to find sum of first 10 natural numbers'
prtip=pp.prot["for"]
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['for']=0
eg.dict_file()
if eg.eggs['nested_for'] and re.search("for.*\s*for", inp):
s='Now, see how `nested for loop` is done in c++ : \n'
f = open("files/nested_for.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to use a nested for loop to print a triangle pattern'
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['for']=0
eg.dict_file()
if eg.eggs['function'] and re.search("def \w{1,}\(\):",inp):
s='Now, see how `functions` are defined in c++ : \n'
f = open("files/function.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to use function to return multiplication of two numbers using return statement'
f.close()
lbl.config(text=s)
playsound('sounds/coin.mp3')
eg.eggs['function']=0
eg.dict_file()
if eg.eggs['comment_line'] and '#'in inp:
s='Now, see `comment line` are used in c++ : \n'
f = open("files/comment.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to use comment line '
lbl.config(text=s)
prtip=pp.prot['comment_line']
playsound('sounds/coin.mp3')
f.close()
eg.eggs['comment_line']=0
eg.dict_file()
if eg.eggs['class'] and re.search('^class',inp):
s='Now, see `classes` are defined in c++ : \n'
f = open("files/class.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to define a class with one variable and one function '
lbl.config(text=s)
playsound('sounds/coin.mp3')
f.close()
eg.eggs['class']=0
eg.dict_file()
if eg.eggs['constructor'] and 'def __init__():'in inp:
s='Now, see how `constructors` of classes are done in c++ : \n'
f = open("files/constructor.cpp", mode='r', encoding='utf-8')
s+=f.read()
s+='\n\nYour task now : to define a function inside a class'
lbl.config(text=s)
playsound('sounds/coin.mp3')
f.close()
eg.eggs['constructor']=0
eg.dict_file()
def run(cmd: str):
cmd = shlex.split(cmd)
return subprocess.run(cmd, stdout=subprocess.PIPE, shell=True).stdout.decode("utf-8")
def outputFunction():
try:
output=run(f"g++ a.cpp && a.exe")
lbl.config(text="Congrats, your code has been accepted!\nOUTPUT:\n"+output)
playsound('sounds/powerup.wav')
#messagebox.showinfo('output', output)
except Exception as e:
playsound('sounds/gameover.mp3')
messagebox.showinfo('Error', e)
def printInput():
inp = textbox2.get(1.0, "end-1c")
with open("a.cpp", "w+") as file:
file.write(inp)
outputFunction()
def out():
inp=textbox1.get(1.0,"end-1 c")
lbl.config(text=inp+'\n\nTry something new and explore!')# need to remove
checker(inp)
def prot():
if not prtip:
protip.config(text='nothing to show')
else:
protip.config(text=prtip)
root=Tk()
heading = Label(root, text="CodeWITHCode", font=("Times new roman", 40, BOLD))
heading.place(x=900, y=20)
protip=Label(root,text="",font=("",14),justify=LEFT,anchor='w')
protip.place(x=700,y=500)
textbox1 = Text(root, bg="black", fg="white")
textbox1.place(x=20, y=20, height=350,)
textbox2 = Text(root, bg="black", fg="white")
textbox2.place(x=670, y=100,width=600,height=400)
probutton = Button(root, text="pro tip", fg="black",command=prot)
probutton.place(x=650, y=540)
submitButton1 = Button(root, text="Run", fg="black",command=out)
submitButton1.place(x=600, y=325)
submitButton2 = Button(root, text="Compile", fg="black",command=printInput)
submitButton2.place(x=1200, y=460)
lbl=Label(root,text='''welcome to our CodeWITHCode\nType your python code in the above box and press run
\nUse The right side box to compile c++ code''',font=("Times new roman",13),justify=LEFT,anchor='w')
lbl.place(x=20,y=400,width=600)
root.geometry("1300x700")
root.mainloop()
if __name__=="__main__":
main()