|
| 1 | +from tkinter import * |
| 2 | +from tkinter import ttk |
| 3 | + |
| 4 | +root = Tk() |
| 5 | + |
| 6 | +root.geometry("800x800") |
| 7 | + |
| 8 | +root.title("Quiz Game App") |
| 9 | + |
| 10 | +scrollbar = Scrollbar(root) |
| 11 | +scrollbar.pack(side=RIGHT, fill=Y) |
| 12 | + |
| 13 | +label = Label(root, text="Software Engineering Quiz ", |
| 14 | + width=28, height=4, font=("algerian", 15)) |
| 15 | +label.pack() |
| 16 | + |
| 17 | + |
| 18 | +class Quiz: |
| 19 | + print('Welcome to the Software Engineering Quiz') |
| 20 | + score = 0 |
| 21 | + total_questions = 4 |
| 22 | + |
| 23 | + def __init__(self): |
| 24 | + # self.ask_question() |
| 25 | + pass |
| 26 | + |
| 27 | + def ask_question(self): |
| 28 | + answer = input('Are you ready to play the Quiz ? (yes/no) :') |
| 29 | + |
| 30 | + if answer.lower() == 'yes': |
| 31 | + answer = input( |
| 32 | + 'Question 1: What programming language was this quiz created in?') |
| 33 | + if answer.lower() == 'python': |
| 34 | + self.score += 1 |
| 35 | + print('correct') |
| 36 | + else: |
| 37 | + print('Wrong Answer :(') |
| 38 | + |
| 39 | + answer = input('Question 2: What is software Engineering?') |
| 40 | + if answer.lower() == 'application of engineering principle to the design a software': |
| 41 | + self.score += 1 |
| 42 | + print('correct') |
| 43 | + else: |
| 44 | + print('Wrong Answer :(') |
| 45 | + |
| 46 | + answer = input('Question 3: what does SDLC stand for?') |
| 47 | + if answer.lower() == 'software Development Life Cycle': |
| 48 | + self.score += 1 |
| 49 | + print('correct') |
| 50 | + else: |
| 51 | + print('Wrong Answer :(') |
| 52 | + |
| 53 | + answer = input( |
| 54 | + 'Question 4: First phase of software development is:') |
| 55 | + if answer.lower() == 'requirement ananlysi': |
| 56 | + self.score += 1 |
| 57 | + print('correct') |
| 58 | + else: |
| 59 | + print('Wrong Answer :(') |
| 60 | + |
| 61 | + print('Thankyou for Playing the Hacktoberfest quiz game, you attempted', |
| 62 | + self.score, "questions correctly!") |
| 63 | + mark = (self.score/self.total_questions)*100 |
| 64 | + print('Marks obtained:', mark) |
| 65 | + print('BYE!') |
| 66 | + |
| 67 | + def get_score(self): |
| 68 | + return self.score |
| 69 | + |
| 70 | + def validate_question_one(self, question_one_value=''): |
| 71 | + if question_one_value.lower() == 'python': |
| 72 | + self.score += 1 |
| 73 | + print('correct') |
| 74 | + else: |
| 75 | + print('Wrong Answer1') |
| 76 | + print('correct answer is python. ') |
| 77 | + return True if question_one_value.lower() == 'python' else False |
| 78 | + |
| 79 | + def validate_question_two(self, question_two_value): |
| 80 | + if question_two_value.lower() == 'application of engineering principle to the design a software': |
| 81 | + self.score += 1 |
| 82 | + print('correct') |
| 83 | + else: |
| 84 | + print('Wrong Answer2') |
| 85 | + print('correct answer is application of engineering principle to the design a software. It is the Application of engineering principles to the design,development, and support of software and it helps to solve the challenges of low- quality software project. ') |
| 86 | + return True if question_two_value.lower() == 'application of engineering principle to the design a software' else False |
| 87 | + |
| 88 | + def validate_question_three(self, question_three_value): |
| 89 | + if question_three_value.lower() == 'software development life cycle': |
| 90 | + self.score += 1 |
| 91 | + print('correct') |
| 92 | + else: |
| 93 | + print('Wrong Answer2') |
| 94 | + print('correct answer is software development life cycle. it is a method for designing, developing, and testing high-quality softwarte.') |
| 95 | + return True if question_three_value.lower() == 'software development life cycle' else False |
| 96 | + |
| 97 | + def validate_question_four(self, question_four_value): |
| 98 | + if question_four_value.lower() == 'requirement ananlysis': |
| 99 | + self.score += 1 |
| 100 | + print('correct') |
| 101 | + else: |
| 102 | + print('Wrong Answer2') |
| 103 | + print('correct answer is requirement ananlysis, as based on it developer design and developed the software.') |
| 104 | + return True if question_four_value.lower() == 'requirement ananlysis' else False |
| 105 | + |
| 106 | + def evaluate(self): |
| 107 | + self.score = 0 |
| 108 | + |
| 109 | + question_one_value = question_one.get() |
| 110 | + self.validate_question_one(question_one_value=question_one_value) |
| 111 | + |
| 112 | + question_two_value = question_two.get() |
| 113 | + self.validate_question_two(question_two_value=question_two_value) |
| 114 | + |
| 115 | + question_three_value = question_three.get() |
| 116 | + self.validate_question_three(question_three_value=question_three_value) |
| 117 | + |
| 118 | + question_four_value = question_four.get() |
| 119 | + self.validate_question_four(question_four_value=question_four_value) |
| 120 | + |
| 121 | + print('Thankyou for Playing the Hacktoberfest quiz game, you attempted', |
| 122 | + self.score, "questions correctly!") |
| 123 | + mark = (self.score/self.total_questions)*100 |
| 124 | + my_label.config(text="Your score is " + str(mark) + "%") |
| 125 | + print('Marks obtained:', mark) |
| 126 | + |
| 127 | + |
| 128 | +quiz = Quiz() |
| 129 | + |
| 130 | +w1_label = Label(root, text="Question 1: What programming language was this quiz created in?", font=( |
| 131 | + "arial", 10), width=100, height=4) |
| 132 | +w1_label.pack() |
| 133 | +question_one = ttk.Combobox( |
| 134 | + root, value=["Python", "Java", "C++"], width=50, height=4) |
| 135 | +w1_label.pack() |
| 136 | +question_one.current(0) |
| 137 | +question_one.pack() |
| 138 | + |
| 139 | +w1_label = Label(root, text="", font=("arial", 10), width=200, height=4) |
| 140 | +w1_label.pack() |
| 141 | + |
| 142 | +w2_label = Label(root, text="Question 2:What is software Engineering?", font=( |
| 143 | + "arial", 10), width=200, height=4) |
| 144 | +w2_label.pack() |
| 145 | +question_two = ttk.Combobox(root, width=50, height=4, value=[ |
| 146 | + "Designing a software", "Testing a software", "Application of engineering principle to the design a software", "None of the above"]) |
| 147 | +question_two.current(0) |
| 148 | +question_two.pack() |
| 149 | + |
| 150 | +w2_label = Label(root, text="", font=("arial", 10), width=200, height=4) |
| 151 | +w2_label.pack() |
| 152 | + |
| 153 | + |
| 154 | +w3_label = Label(root, text="Question 3:what does SDLC stand for?", |
| 155 | + font=("arial", 10), width=200, height=4) |
| 156 | +w3_label.pack() |
| 157 | +question_three = ttk.Combobox(root, width=50, height=4, value=[ |
| 158 | + "System Design Life Cycle", "Software Design Life Cycle", "System Development Life Cycle", "Software Development Life Cycle"]) |
| 159 | +question_three.current(0) |
| 160 | +question_three.pack() |
| 161 | + |
| 162 | +w3_label = Label(root, text="", font=("arial", 10), width=200, height=4) |
| 163 | +w3_label.pack() |
| 164 | + |
| 165 | +w4_label = Label(root, text="Question 4: First phase of software development is:", font=( |
| 166 | + "arial", 10), width=200, height=4) |
| 167 | +w4_label.pack() |
| 168 | +question_four = ttk.Combobox(root, width=50, height=4, value=[ |
| 169 | + "Coding", "Testing", "Design", "Requirement ananlysis"]) |
| 170 | +question_four.current(0) |
| 171 | +question_four.pack() |
| 172 | + |
| 173 | +w4_label = Label(root, text="", font=("arial", 10), width=200, height=4) |
| 174 | +w4_label.pack() |
| 175 | + |
| 176 | + |
| 177 | +button = Button(root, text="Submit", font=( |
| 178 | + "bell mt", 10), command=quiz.evaluate) |
| 179 | +button.pack() |
| 180 | + |
| 181 | + |
| 182 | +# w6_label = Label(root,font=("arial",10),width=100,height=4, textvariable=quiz.get_score()) |
| 183 | +my_label = Label(root, |
| 184 | + text="Score:") |
| 185 | +my_label.pack() |
| 186 | + |
| 187 | + |
| 188 | +root.mainloop() |
0 commit comments