1+ from PyQt5 .QtWidgets import QPushButton , QLabel , QWidget
2+ from PyQt5 .QtGui import QFont
3+ from PyQt5 .QtCore import Qt
4+ import os
5+ import sys
6+ import random
7+
8+ qu10 = None
9+ ans = 0
10+
11+ # Main function for the tenth 'Easy' quiz question
12+ # Receives the window, previous score, and correctness of previous questions
13+ # Sets up the tenth question and answer buttons
14+
15+ def easy (window , ans9 , qu9 , qu8 , qu7 , qu6 , qu5 , qu4 , qu3 , qu2 , qu1 ):
16+ global qu10 , ans
17+ ans += ans9 # Add previous score to current score
18+ font = QFont ("Calibri" , 13 )
19+ instance = random .randint (1 , 3 ) # Randomly select which question to show
20+
21+ # Create the question label, centered horizontally
22+ question = QLabel ("" , window )
23+ question .setFont (font )
24+ question .setAlignment (Qt .AlignCenter )
25+
26+ # Set the question text based on the random variant (all in English)
27+ if instance == 1 :
28+ question .setText ('''10. What is the currency of Sweden?''' )
29+ elif instance == 2 :
30+ question .setText ('''10. In which country is Ben Nevis,
31+ the highest peak of the Cambrian Mountains, located?''' )
32+ elif instance == 3 :
33+ question .setText ('''10. Which country has the most islands in Europe?''' )
34+
35+ # Calculate position to center the label horizontally and place it near the top
36+ window_width = window .frameGeometry ().width ()
37+ question_width = 600
38+ question_height = 100
39+ question_x = (window_width - question_width ) // 2
40+ question_y = 20
41+ question .setGeometry (question_x , question_y , question_width , question_height )
42+ question .setStyleSheet ("font-size: 20px; font-weight: bold;" )
43+ question .show ()
44+
45+ # Function to proceed to the results screen (calls easy_marks.show_marks)
46+ def next_question ():
47+ import marks
48+ # Remove all widgets from the window before showing the results
49+ for widget in window .children ():
50+ widget .deleteLater ()
51+ print (ans )
52+ print (qu10 )
53+ marks .show_marks (window , ans , qu10 , qu9 , qu8 , qu7 , qu6 , qu5 , qu4 , qu3 , qu2 , qu1 )
54+
55+ # Answer button callbacks for each possible answer
56+ # Each function checks which question is active and updates the score and correctness accordingly
57+ def answer_dania ():
58+ global qu10 , ans
59+ if instance == 1 :
60+ qu10 = False
61+ next_question ()
62+ elif instance == 2 :
63+ qu10 = False
64+ next_question ()
65+ elif instance == 3 :
66+ qu10 = False
67+ next_question ()
68+
69+ def answer_kroatia ():
70+ global qu10 , ans
71+ if instance == 1 :
72+ qu10 = True
73+ ans += 2
74+ next_question ()
75+ elif instance == 2 :
76+ qu10 = False
77+ next_question ()
78+ elif instance == 3 :
79+ qu10 = False
80+ next_question ()
81+
82+ def answer_norway ():
83+ global qu10 , ans
84+ if instance == 1 :
85+ qu10 = False
86+ next_question ()
87+ elif instance == 2 :
88+ qu10 = True
89+ ans += 2
90+ next_question ()
91+ elif instance == 3 :
92+ qu10 = False
93+ next_question ()
94+
95+ def answer_lichtenstain ():
96+ global qu10 , ans
97+ if instance == 1 :
98+ qu10 = False
99+ next_question ()
100+ elif instance == 2 :
101+ qu10 = False
102+ next_question ()
103+ elif instance == 3 :
104+ qu10 = True
105+ ans += 2
106+ next_question ()
107+
108+ # Set the button texts according to the question instance (all in English)
109+ def set_correct_text ():
110+ if instance == 1 :
111+ dania .setText ("A) Euro" )
112+ kroatia .setText ("B) Krona" )
113+ norway .setText ("C) Franc" )
114+ poland .setText ("D) Pound" )
115+ if instance == 2 :
116+ dania .setText ("A) Ireland" )
117+ kroatia .setText ("B) England" )
118+ norway .setText ("C) Scotland" )
119+ poland .setText ("D) Wales" )
120+ if instance == 3 :
121+ dania .setText ("A) Italy" )
122+ kroatia .setText ("B) Greece" )
123+ norway .setText ("C) Norway" )
124+ poland .setText ("D) Sweden" )
125+
126+ # Create answer buttons and connect them to the correct callback
127+ dania = QPushButton ("A) Denmark" , window )
128+ dania .resize (500 , 120 )
129+ dania .move (250 , 140 )
130+ dania .setFont (font )
131+ dania .show ()
132+ dania .clicked .connect (answer_dania )
133+
134+ kroatia = QPushButton ("B) Croatia" , window )
135+ kroatia .setFont (font )
136+ kroatia .resize (500 , 120 )
137+ kroatia .move (250 , 270 )
138+ kroatia .show ()
139+ kroatia .clicked .connect (answer_kroatia )
140+
141+ norway = QPushButton ("C) Norway" , window )
142+ norway .resize (500 , 120 )
143+ norway .move (250 , 400 )
144+ norway .setFont (font )
145+ norway .show ()
146+ norway .clicked .connect (answer_norway )
147+
148+ poland = QPushButton ("D) Liechtenstein" , window )
149+ poland .resize (500 , 120 )
150+ poland .move (250 , 530 )
151+ poland .setFont (font )
152+ poland .show ()
153+ poland .clicked .connect (answer_lichtenstain )
154+ set_correct_text ()
0 commit comments