Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Smart E- Learn Tracer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
23_22 - J 01
Smart E- Learn Tracer
Commits
36bf6116
Commit
36bf6116
authored
May 15, 2023
by
Niyas Inshaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
b34e01b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
Qiz_Genaration
Qiz_Genaration
+55
-0
No files found.
Qiz_Genaration
0 → 100644
View file @
36bf6116
from questions import quiz
def check_ans(question, ans, attempts, score):
"""
Takes the arguments, and confirms if the answer provided by user is correct.
Converts all answers to lower case to make sure the quiz is not case sensitive.
"""
if quiz[question]['answer'].lower() == ans.lower():
print(f"Correct Answer! \nYour score is {score + 1}!")
return True
else:
print(f"Wrong Answer :( \nYou have {attempts - 1} left! \nTry again...")
return False
def print_dictionary():
for question_id, ques_answer in quiz.items():
for key in ques_answer:
print(key + ':', ques_answer[key])
def intro_message():
"""
Introduces user to the quiz and rules, and takes an input from customer to start the quiz.
Returns true regardless of any key pressed.
"""
print("Welcome to this fun food quiz! \nAre you ready to test your knowledge about food?")
print("There are a total of 20 questions, you can skip a question anytime by typing 'skip'")
input("Press any key to start the fun ;) ")
return True
# python project.py
intro = intro_message()
while True:
score = 0
for question in quiz:
attempts = 3
while attempts > 0:
print(quiz[question]['question'])
answer = input("Enter Answer (To move to the next question, type 'skip') : ")
if answer == "skip":
break
check = check_ans(question, answer, attempts, score)
if check:
score += 1
break
attempts -= 1
break
print(f"Your final score is {score}!\n\n")
print("Want to know the correct answers? Please see them below! ;)\n")
print_dictionary()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment