quiz game
Transcript: TOPIC QUIZ GAME BY 210071601132 &210071601133 OBJ. OBJECTIVE TO SPREAD GENERAL KNOWLADGE TO USERS IN A FUN MANNER WHEN THEY WISH TO TIME PASS. CODE TKINTER: IT IS A MODULE IN PYTHON.IT IS USED AND THE MOST BASIC GUI FRAMEWORK IS USED I PYTHON PROGRAMMING.TKINTER PROVIDES A POWERFUL OBJECT ORIENTED INTERFACE TO THE TK GUI TOOLKIT. IMPLEMENTATION CODE IMPLEMENTATION: IN THIS WAY WE HAVE TO IMPORT THESE MODULES from tkinter import * from tkinter import font we can add the mcq options through: def start_again(): global Score,Question_no Score = 0 Question_no = 1 next_b.config(text="next") val1.set(0) val2.set(0) val3.set(0) question.config(text=Questions[Question_no-1]) option1.config(text=Options[Question_no-1][0]) option2.config(text=Options[Question_no-1][1]) option3.config(text=Options[Question_no-1][2]) play_again.place_forget() score_output.place_forget() root.pack() FUNCTIONS HERE WE DEFINE DIFFERENT FUNCTIONS: def start_again(): Short description here def next(): def Check(Option): Short description here Short description here SOURCE CODE SOURCE CODE from tkinter import * from tkinter import font def start_again(): global Score,Question_no Score = 0 Question_no = 1 next_b.config(text="Next") val1.set(0) val2.set(0) val3.set(0) question.config(text=Questions[Question_no-1]) question.configure(background="purple") option1.config(text=Options[Question_no-1][0]) option1.configure(background="purple") option2.config(text=Options[Question_no-1][1]) option2.configure(background="purple") option3.config(text=Options[Question_no-1][2]) option3.configure(background="purple") play_again.place_forget() score_output.place_forget() root.pack() def next(): global Score,Question_no if(val1.get()): selected_option = 1 elif(val2.get()): selected_option = 2 elif(val3.get()): selected_option = 3 else: selected_option = -1 if(Answers[Question_no-1] == selected_option): Score += 1 if(Question_no == Total_No_Questions-1): next_b.config(text="Submit") Question_no = Question_no + 1 if(Question_no > Total_No_Questions): root.pack_forget() score_output.place(relx=.45,rely=.45) play_again.place(relx = .45) score_output.config(text = "Score: " +str(Score)) else: val1.set(0) val2.set(0) val3.set(0) question.config(text=Questions[Question_no-1]) question.configure(background="purple") option1.config(text=Options[Question_no-1][0]) option1.configure(background="purple") if(Question_no > Total_No_Questions): root.pack_forget() score_output.place(relx=.45,rely=.45) play_again.place(relx = .45) score_output.config(text = "Score: " +str(Score)) else: val1.set(0) val2.set(0) val3.set(0) question.config(text=Questions[Question_no-1]) question.configure(background="purple") option1.config(text=Options[Question_no-1][0]) option1.configure(background="purple") option2.config(text=Options[Question_no-1][1]) option2.configure(background="purple") option3.config(text=Options[Question_no-1][2]) option3.configure(background="purple") def Check(Option): if(Option == 1): # val1.set(1) val2.set(0) val3.set(0) elif(Option == 2): val1.set(0) # val2.set(1) val3.set(0) elif(Option == 3): val1.set(0) val2.set(0) # val3.set(1) Questions = ["What country has won the most World Cups?" , "In 2010, which one of these teams was not in the semifinals?" , "What’s the host country for the 2022 World Cup?"] Options = [["Argentina","Germany", "Brazil"], ["Spain","England", "Uruguay"], ["K.S.A","U.A.E", "Qatar"]] Answers = [3 , 2 , 3] Score = 0 Total_No_Questions = 3 Question_no = 1 Win= Tk() Win.title("Quiz Game") root = Frame(Win) root.pack() root.configure(background="purple") question = Label(root,width = 60,font=(10),text=Questions[0]) question.pack(fill=X) val1 = IntVar() val2 = IntVar() val3 = IntVar() option1 = Checkbutton(root,variable=val1,text=Options[0][0],command=lambda:Check(1)) option1.pack() option2 = Checkbutton(root,variable=val2,text=Options[0][1],command=lambda:Check(2)) option2.pack() option3 = Checkbutton(root,variable=val3,text=Options[0][2],command=lambda:Check(3)) option3.pack() next_b = Button(root , text = "Next",command=next) next_b.pack() score_output = Label(Win,font=(50)) score_output.place_forget() play_again = Button(Win,text= "Play Again",command=start_again) play_again.place_forget() Win.configure(background="black") Win.mainloop() OUTPUT THIS IS THE OUTPUT OF THE CODE.WE CAN SEE A QUIZ HAS APPEARED WHICH CONTAINS THREE OPTIONS AND ON SELECTING THE CORRECT OPTIONS YOUR SCORE WILL BE SHOWN. OUTPUT