Skip to content

Commit 1990c17

Browse files
committed
Update code based on TR
1 parent 5d8aa50 commit 1990c17

File tree

2 files changed

+4
-4
lines changed
  • python-quiz-application

2 files changed

+4
-4
lines changed

python-quiz-application/source_code_final/quiz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def ask_question(question):
5252
num_choices=len(correct_answers),
5353
hint=question.get("hint"),
5454
)
55-
if set(answers) == set(correct_answers):
55+
if correct := (set(answers) == set(correct_answers)):
5656
print("⭐ Correct! ⭐")
5757
else:
5858
is_or_are = " is" if len(correct_answers) == 1 else "s are"
@@ -61,7 +61,7 @@ def ask_question(question):
6161
if "explanation" in question:
6262
print(f"\nEXPLANATION:\n{question['explanation']}")
6363

64-
return 1 if set(answers) == set(correct_answers) else 0
64+
return 1 if correct else 0
6565

6666

6767
def get_answers(question, alternatives, num_choices=1, hint=None):

python-quiz-application/source_code_step_5/quiz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def ask_question(question):
4343
num_choices=len(correct_answers),
4444
hint=question.get("hint"),
4545
)
46-
if set(answers) == set(correct_answers):
46+
if correct := (set(answers) == set(correct_answers)):
4747
print("⭐ Correct! ⭐")
4848
else:
4949
is_or_are = " is" if len(correct_answers) == 1 else "s are"
@@ -52,7 +52,7 @@ def ask_question(question):
5252
if "explanation" in question:
5353
print(f"\nEXPLANATION:\n{question['explanation']}")
5454

55-
return 1 if set(answers) == set(correct_answers) else 0
55+
return 1 if correct else 0
5656

5757

5858
def get_answers(question, alternatives, num_choices=1, hint=None):

0 commit comments

Comments
 (0)