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
06d05bc0
Commit
06d05bc0
authored
Oct 07, 2022
by
Niyas Inshaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
My First file (NLP Automated Quiz)
parent
abaf3567
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
nlp_quiz.py
nlp_quiz.py
+55
-0
No files found.
nlp_quiz.py
0 → 100644
View file @
06d05bc0
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!
\n
Your score is {score + 1}!"
)
return
True
else
:
print
(
f
"Wrong Answer :(
\n
You have {attempts - 1} left!
\n
Try 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!
\n
Are 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
()
\ No newline at end of file
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