-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_code
More file actions
188 lines (156 loc) · 12.8 KB
/
Copy pathmain_code
File metadata and controls
188 lines (156 loc) · 12.8 KB
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
from tkinter import *
import random
root = Tk()
root.title("CodesQuiz")
root.geometry("700x500")
root.config(background='black')
root.resizable(0,0)
py_questions=["Find the output: \n var= 'Meow' * 2 * 3 \n print(var)","Find the output: \n x = 36 / 4 * (3 + 2) * 4 + 2 \n print(x)","def calculate (num1, num2=4): \n total = num1 * num2 \n print(total) \n calculate(5, 6)", "Find the output: \n listOne = [20, 40, 60, 80] \n listTwo = [20, 40, 60, 80] \n print(listOne == listTwo, listOne is listTwo)" ,"What is NOT a legal variable name?","What is the file extension for Python files?","Which operator can be used to compare two values?","Which of these is a dictionary?","What is the syntax to find the type of the variable or object in python?","age=input('Enter your age') \n new_age=20+age \n print(new_age) \n You enter - 15. What is the ouput?"]
py_answers=[["MeowMeowMeowMeowMeowMeow","MeowMeowMeowMeowMeow","Error:Invalid Syntax","Meow23"],["182.0","78.0","78","182"],["20","30","24","Program is executed with an error"],["True True","True False","False False","False True"],["MyVariable","1MyVariable","my_variable","MyVariable_"],[".py",".pt",".pyth",".pyt"],["=","==","<>","><"],["Countries=(India, Canada)","Countries = {India, Canada}","Countries=[India, Canada]","Countries = {India:Delhi, Canada:Ottawa}"],["print(typeof(x))","print(typeOf(x))","print(type(x))","print(typeof x)"],["2015","35","Program is executed with an error","None of the above"]]
c_questions=['A C++ program statements can be commented using:','Which method can be used to find the length of a string?','Which operator is used to add together two values?','Which header file lets us work with input and output objects?','How do you create a function in C++?','What is the correct way to create an object called myObj of MyClass?','Which statement is used to stop a loop?','What is the only function all C++ programs must contain?','What punctuation ends most lines of C++ code?','Which of the following is not a correct variable type?']
c_answers=[['Single line comment','Multi line comment','Either (a) or (b)','Both (a) and (b)'],['getLength() ','len() ','length() ','getSize() '],['The & sign','The + sign','The * sign','None of the above'],['#include <inputstr>','> #include <stream>','#include <iosstring>','> #include <iostream> '],['functionName()','functionName.','functionName[]','(functionName)'],['class MyClass = new myObj(); ','class myObj = new MyClass();','MyClass myObj; ','new myObj = MyClass();'],['break','exit','stop','return'],['start()','system()','main()','program()'],['.',';',':','"'],['float','real','int','double']]
correct_ans_py=[0,0,1,1,0,1,3,2,2,1]
correct_ans_c=[3,2,1,3,0,2,0,2,1,1]
def endApp():
root.destroy()
def cExplanation():
global question, answer
logo1.destroy()
title.destroy()
q2.destroy()
op5.destroy()
op6.destroy()
op7.destroy()
op8.destroy()
i=1
while(i<11):
c_questions = ['A C++ program statements can be commented using:','Which method can be used to find the length of a string?','Which operator is used to add together two values?','Which header file lets us work with input and output objects?','How do you create a function in C++?','What is the correct way to create an object called myObj of MyClass?','Which statement is used to stop a loop?','What is the only function all C++ programs must contain?','What punctuation ends most lines of C++ code?','Which of the following is not a correct variable type?']
c_answers=[['Single line comment //','Multi line comment /* */','Either (a) or (b)','Both (a) and (b)'],['getLength() ','len() ','length() ','getSize() '],['The & sign','The + sign','The * sign','None of the above'],['#include <inputstr>','#include <stream>','#include <iosstring>',' #include <iostream> '],['functionName()','functionName.','functionName[]','(functionName)'],['class MyClass = new myObj(); ','class myObj = new MyClass();','MyClass myObj; ','new myObj = MyClass();'],['break','exit','stop','return'],['start()','system()','main()','program()'],['.',';',':','"'],['float','real','int','double']]
c_explain=["If you need to comment a block of lines, you can use multiline. Otherwise, single line works","Everything other than length() is invalid in C++","The addition operator is used to add 2 values", "iostream stands for input output stream and we include this header file","A function is created by writing the function name followed by () which can hold arguments","An object is created by writing the name of the class followed by the name of the object","'break' breaks out of a loop, exit exits the program, return returns some value to the caller function","The main function is mandatory to run the program","It is what it is c:","real is invalid and cannot be used to denote any datatype"]
question=Label(root, text="Question: "+c_questions[i-1], background="black", foreground="white", font=('Comic sans MS',10), justify="left")
question.pack()
answer=Label(root, text="Answer: "+c_answers[i-1][correct_ans_c[i-1]]+"("+c_explain[i-1]+")",background='magenta',font=('Comic sans MS',10))
answer.pack()
i+=1
end=Button(root, text='Exit', command=endApp, font=('Comic sans ms', 18), background='red')
end.place(relx=0.83, rely=0.0, relwidth=0.15, relheight=0.05)
def pyExplanation():
global question, answer, next
logo1.destroy()
title.destroy()
q1.destroy()
op1.destroy()
op2.destroy()
op3.destroy()
op4.destroy()
i=1
while(i<11):
py_questions=["Find the output: var= 'Meow' * 2 * 3 print(var)","Find the output: x = 36 / 4 * (3 + 2) * 4 + 2 print(x)", "Find the output: listOne = [20, 40] listTwo = [20, 40] \nprint(listOne == listTwo, listOne is listTwo)" ,"What is NOT a legal variable name?","What is the file extension for Python files?","Which operator can be used to compare two values?","Which of these is a dictionary?","What is the syntax to find the type of the variable or object in python?","age=input('Enter your age') new_age=20+age print(new_age) You enter - 15. What is the ouput?", "def calculate (num1, num2=4): total = num1 * num2 print(total) calculate(5, 6)"]
py_answers=[["MeowMeowMeowMeowMeowMeow","MeowMeowMeowMeowMeow","Error:Invalid Syntax","Meow23"],["182.0","78.0","78","182"],["True True","True False","False False","False True"],["MyVariable","1MyVariable","my_variable","MyVariable_"],[".py",".pt",".pyth",".pyt"],["=","==","<>","><"],["Countries=(India, Canada)","Countries = {India, Canada}","Countries=[India, Canada]","Countries = {India:Delhi, Canada:Ottawa}"],["print(typeof(x))","print(typeOf(x))","print(type(x))","print(typeof x)"],["2015","35","Program is executed with an error","None of the above"], ["20","30","24","Program is executed with an error"]]
py_explain=["A string * with int just multiplies the string those many times", "We follow BODMAS and since the highest precedence is int, there is no floating point after 182. ", "'is' checks if 2 variables belong to the same object. == checks if the 2 variables have equal value", "variable names should only start with letters or underscore _","It is what it is :) ","= is an assignment operator, == is used for checking equality","() is a tuple, {} is a set, [] is a list, {key:value} is a dictionary","typeof and typeOf are invalid in python. X should always be in a () for inbuilt functions","'input' converts input to string. We cannot add a string and integer","Function arguments are given more importance compared to default values. Hence 5*6 is calculated"]
question=Label(root, text="Question: "+py_questions[i-1], background="black", foreground="white", font=('Comic sans MS',10), justify="left")
answer=Label(root, text="Ans: "+py_answers[i-1][correct_ans_py[i-1]] +"("+ py_explain[i-1]+")",background='magenta',font=('Comic sans MS',10), justify="left")
question.pack()
answer.pack()
i+=1
end=Button(root, text='Exit', command=endApp, font=('Comic sans ms', 18), background='red')
end.place(relx=0.83, rely=0.0, relwidth=0.15, relheight=0.05)
user_ans=[]
ques=1
def selectedPy():
global options1, user_ans,q1, op1,op2, op3, op4, ques
num=options1.get()
user_ans.append(num)
options1.set(-1)
if ques < 10:
q1.config(text=py_questions[index[ques]])
op1['text']=py_answers[index[ques]][0]
op2['text']=py_answers[index[ques]][1]
op3['text']=py_answers[index[ques]][2]
op4['text']=py_answers[index[ques]][3]
ques+=1
else:
pyExplanation()
def selectedC():
global options2, user_ans,q2, op5,op6, op7, op8, ques
num=options2.get()
user_ans.append(num)
options2.set(-1)
if ques < 10:
q2.config(text=c_questions[index[ques]])
op5['text']=c_answers[index[ques]][0]
op6['text']=c_answers[index[ques]][1]
op7['text']=c_answers[index[ques]][2]
op8['text']=c_answers[index[ques]][3]
ques+=1
else:
cExplanation()
def startCPlusPlus():
cplusplus.destroy()
python.destroy()
global options2, q2, op5, op6, op7, op8
q2=Label(root, text=c_questions[index[0]], font=('AR CENA',14), justify= 'center', wraplength = 400)
q2.place(relx=0.2, rely=0.4, relwidth=0.635, relheight=0.18)
options2=IntVar()
options2.set(-1)
op5 = Radiobutton(root,text= c_answers[index[0]][0], font=('Arial',11),value=0, variable = options2, command=selectedC)
op5.place(relx=0.3, rely=0.6, relwidth=0.435, relheight=0.08)
op6 = Radiobutton(root,text=c_answers[index[0]][1], font=('Arial',11),value=1, variable = options2, command=selectedC)
op6.place(relx=0.3, rely=0.7, relwidth=0.435, relheight=0.08)
op7 = Radiobutton(root,text= c_answers[index[0]][2],font=('Arial',11), value=2, variable = options2, command=selectedC)
op7.place(relx=0.3, rely=0.8, relwidth=0.435, relheight=0.08)
op8 = Radiobutton(root,text= c_answers[index[0]][3], font=('Arial',11), value=3, variable = options2, command=selectedC)
op8.place(relx=0.3, rely=0.9, relwidth=0.435, relheight=0.08)
def startPython():
python.destroy()
cplusplus.destroy()
global options1, q1, op1, op2, op3, op4
q1=Label(root, text=py_questions[index[0]], font=('AR CENA',14), justify= 'center', wraplength = 400)
q1.place(relx=0.2, rely=0.4, relwidth=0.635, relheight=0.18)
options1=IntVar()
options1.set(-1)
op1 = Radiobutton(root,text= py_answers[index[0]][0], font=('Arial',11),value=0, variable = options1, command=selectedPy)
op1.place(relx=0.3, rely=0.6, relwidth=0.435, relheight=0.08)
op2 = Radiobutton(root,text=py_answers[index[0]][1], font=('Arial',11),value=1, variable = options1, command=selectedPy)
op2.place(relx=0.3, rely=0.7, relwidth=0.435, relheight=0.08)
op3 = Radiobutton(root,text= py_answers[index[0]][2],font=('Arial',11), value=2, variable = options1, command=selectedPy)
op3.place(relx=0.3, rely=0.8, relwidth=0.435, relheight=0.08)
op4 = Radiobutton(root,text= py_answers[index[0]][3], font=('Arial',11), value=3, variable = options1, command=selectedPy)
op4.place(relx=0.3, rely=0.9, relwidth=0.435, relheight=0.08)
def giveChoice():
global python, cplusplus
python=Button(root, text='Python',command=startPython, background='white',font=('Times',16))
python.place(relx=0.15,rely=0.4,relheight=0.1, relwidth=0.3)
cplusplus=Button(root, text='C++', command=startCPlusPlus, background='white',font=('Times',16))
cplusplus.place(relx=0.55,rely=0.4,relheight=0.1, relwidth=0.3)
index=[]
def randomGen():
global index
while len(index)<10:
randomNumber=random.randint(0,9)
if randomNumber in index:
continue
else:
index.append(randomNumber)
def pressStart():
start_game.destroy()
startButton.destroy()
instructions.destroy()
help.destroy()
randomGen()
giveChoice()
logoImg = PhotoImage(file='logo.png')
logo1 = Label(root, image=logoImg, background="black")
logo1.pack()
title = Label(root, text='CodesQuiz', font=('Comic sans MS', 20), background='red')
title.pack()
help = Label(root, text='Check rules below and start the game.', font=('Comic sans MS', 17), background='light blue')
help.place(relx=0.20, rely=0.35, relwidth=0.59, relheight=0.10)
startImg=PhotoImage(file="start.png")
start_game=Label(root, image=startImg, background='black')
start_game.place(relx=0.75, rely=0.55, relwidth=0.3, relheight=0.15)
startButton=Button(root, text='Start Quiz', command=pressStart, font=('Comic sans ms', 20), background='red')
startButton.place(relx=0.55, rely=0.55, relwidth=0.25, relheight=0.15)
instructions=Label(root,text="A series of coding questions will be asked about Python/C++. \n Out of the 4 options provided, choose one.\n Irrespective of whether your answer is right or wrong,\n the answers will be provided. Learn and Enjoy!", font=('Comic sans ms', 14), background='light blue')
instructions.pack(side='bottom')
root.mainloop()