|
| 1 | +from tkinter import * |
| 2 | +from tkinter import ttk |
| 3 | + |
| 4 | +root = Tk() |
| 5 | + |
| 6 | +root.geometry("500x500") |
| 7 | + |
| 8 | +root.title("Hacktoberfest Quiz") |
| 9 | + |
| 10 | + |
| 11 | +label = Label(root,text="Hacktoberfest Quiz ",width = 20,height=4,font=("algerian",15)) |
| 12 | +label.pack() |
| 13 | + |
| 14 | +class Quiz: |
| 15 | + print('Welcome to the Hacktoberfest 2022 Quiz') |
| 16 | + score=0 |
| 17 | + total_questions=4 |
| 18 | + |
| 19 | + def __init__(self): |
| 20 | + # self.ask_question() |
| 21 | + pass |
| 22 | + |
| 23 | + def ask_question(self): |
| 24 | + answer=input('Are you ready to play the Quiz ? (yes/no) :') |
| 25 | + |
| 26 | + if answer.lower()=='yes': |
| 27 | + answer=input('Question 1: What programming language was this quiz created in? Hint: Java, C++, Python') |
| 28 | + if answer.lower()=='python': |
| 29 | + self.score += 1 |
| 30 | + print('correct') |
| 31 | + else: |
| 32 | + print('Wrong Answer :(') |
| 33 | + |
| 34 | + |
| 35 | + answer=input('Question 2: Is one of the values of Hacktoberfest 2022 "EVERYONE IS WELCOME" ? ') |
| 36 | + if answer.lower()=='yes': |
| 37 | + self.score += 1 |
| 38 | + print('correct') |
| 39 | + else: |
| 40 | + print('Wrong Answer :(') |
| 41 | + |
| 42 | + answer=input('Question 3: Does Hacktoberfest end on December 31?') |
| 43 | + if answer.lower()=='no': |
| 44 | + self.score += 1 |
| 45 | + print('correct') |
| 46 | + else: |
| 47 | + print('Wrong Answer :(') |
| 48 | + |
| 49 | + answer=input('Question 3: Does Hacktoberfest have a discord server?') |
| 50 | + if answer.lower()=='yes': |
| 51 | + self.score += 1 |
| 52 | + print('correct') |
| 53 | + else: |
| 54 | + print('Wrong Answer :(') |
| 55 | + |
| 56 | + print('Thankyou for Playing the Hacktoberfest quiz game, you attempted',self.score,"questions correctly!") |
| 57 | + mark=(self.score/self.total_questions)*100 |
| 58 | + print('Marks obtained:',mark) |
| 59 | + print('BYE!') |
| 60 | + |
| 61 | + def get_score(self): |
| 62 | + return self.score |
| 63 | + |
| 64 | + def validate_question_one(self, question_one_value = ''): |
| 65 | + if question_one_value.lower()=='python': |
| 66 | + self.score += 1 |
| 67 | + print('correct') |
| 68 | + else: |
| 69 | + print('Wrong Answer1') |
| 70 | + print('correct answer is python ') |
| 71 | + return True if question_one_value.lower()=='python' else False |
| 72 | + |
| 73 | + def validate_question_two(self, question_two_value): |
| 74 | + if question_two_value.lower()=='yes': |
| 75 | + self.score += 1 |
| 76 | + print('correct') |
| 77 | + else: |
| 78 | + print('Wrong Answer2') |
| 79 | + print('correct answer is yes ') |
| 80 | + return True if question_two_value.lower()=='yes' else False |
| 81 | + |
| 82 | + def validate_question_three(self, question_three_value): |
| 83 | + if question_three_value.lower()=='no': |
| 84 | + self.score += 1 |
| 85 | + print('correct') |
| 86 | + else: |
| 87 | + print('Wrong Answer2') |
| 88 | + print('correct answer is no') |
| 89 | + return True if question_three_value.lower()=='no' else False |
| 90 | + |
| 91 | + def validate_question_four(self, question_four_value): |
| 92 | + if question_four_value.lower()=='yes': |
| 93 | + self.score += 1 |
| 94 | + print('correct') |
| 95 | + else: |
| 96 | + print('Wrong Answer2') |
| 97 | + print('correct answer is yes') |
| 98 | + return True if question_four_value.lower()=='yes' else False |
| 99 | + |
| 100 | + def evaluate(self): |
| 101 | + self.score = 0 |
| 102 | + |
| 103 | + question_one_value = question_one.get() |
| 104 | + self.validate_question_one(question_one_value=question_one_value) |
| 105 | + |
| 106 | + question_two_value = question_two.get() |
| 107 | + self.validate_question_two(question_two_value=question_two_value) |
| 108 | + |
| 109 | + question_three_value = question_three.get() |
| 110 | + self.validate_question_three(question_three_value=question_three_value) |
| 111 | + |
| 112 | + question_four_value = question_four.get() |
| 113 | + self.validate_question_four(question_four_value=question_four_value) |
| 114 | + |
| 115 | + |
| 116 | + print('Thankyou for Playing the Hacktoberfest quiz game, you attempted',self.score,"questions correctly!") |
| 117 | + mark=(self.score/self.total_questions)*100 |
| 118 | + my_label.config(text = "Your score is " + str(mark) +"%") |
| 119 | + print('Marks obtained:',mark) |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +quiz = Quiz() |
| 125 | + |
| 126 | +w1_label = Label(root,text="Question 1: What programming language was this quiz created in? Hint: Java, C++, Python ?",font=("arial",10),width=100,height=4) |
| 127 | +w1_label.pack() |
| 128 | +question_one = ttk.Combobox(root,value=["Python","Java","C++"]) |
| 129 | +question_one.current(0) |
| 130 | +question_one.pack() |
| 131 | + |
| 132 | +w1_label = Label(root,text="",font=("arial",10),width=100,height=4) |
| 133 | +w1_label.pack() |
| 134 | + |
| 135 | +w2_label = Label(root,text="Question 2: Is one of the values of Hacktoberfest 2022 'EVERYONE IS WELCOME' ?",font=("arial",10),width=100,height=4) |
| 136 | +w2_label.pack() |
| 137 | +question_two = ttk.Combobox(root,value=["Yes","No"]) |
| 138 | +question_two.current(0) |
| 139 | +question_two.pack() |
| 140 | + |
| 141 | +w2_label = Label(root,text="",font=("arial",10),width=100,height=4) |
| 142 | +w2_label.pack() |
| 143 | + |
| 144 | + |
| 145 | +w3_label = Label(root,text="Question 3: Does Hacktoberfest end on December 31?",font=("arial",10),width=100,height=4) |
| 146 | +w3_label.pack() |
| 147 | +question_three = ttk.Combobox(root,value=["Yes","No"]) |
| 148 | +question_three.current(0) |
| 149 | +question_three.pack() |
| 150 | + |
| 151 | +w3_label = Label(root,text="",font=("arial",10),width=100,height=4) |
| 152 | +w3_label.pack() |
| 153 | + |
| 154 | +w4_label = Label(root,text="Question 4: Does Hacktoberfest have a discord server?",font=("arial",10),width=50,height=4) |
| 155 | +w4_label.pack() |
| 156 | +question_four = ttk.Combobox(root,value=["Yes","No"]) |
| 157 | +question_four.current(0) |
| 158 | +question_four.pack() |
| 159 | + |
| 160 | +w4_label = Label(root,text="",font=("arial",10),width=50,height=4) |
| 161 | +w4_label.pack() |
| 162 | + |
| 163 | + |
| 164 | +button = Button(root,text="Submit",font=("bell mt",10), command=quiz.evaluate) |
| 165 | +button.pack() |
| 166 | + |
| 167 | + |
| 168 | +# w6_label = Label(root,font=("arial",10),width=100,height=4, textvariable=quiz.get_score()) |
| 169 | +my_label = Label(root, |
| 170 | + text = "Score:") |
| 171 | +my_label.pack() |
| 172 | + |
| 173 | + |
| 174 | +root.mainloop() |
0 commit comments