Python Quiz
This is the quiz that is made using Python.
The Python quiz is below. There will be a 6 questions in which you will have to answer. Good luck!
import getpass, sys
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
questions = 6
correct = 0
# Confirmation to take the quiz
print('Hello, ' + getpass.getuser() + " running on" + sys.executable + "!")
print("You will be asked " + str(questions) + " questions.")
question_with_response("Are you ready to take a quiz?")
# Question 1
rsp = question_with_response("What command is used to include other functions that were previously developed?")
if rsp == "import":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Question 2
rsp = question_with_response("What command is used to evaluate correct or incorrect response in this example?")
if rsp == "if":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Question 3
rsp = question_with_response("Each 'if' command contains an '_________' to determine a true or false condition?")
if rsp == "expression":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Question 4
rsp = question_with_response("What is a sequence?")
if rsp == "two or more lines of code":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Question 5
rsp = question_with_response("Which function turns a number into a string?")
if rsp == "str()":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Question 6
rsp = question_with_response("Which key word in Python defines a function?")
if rsp == "def":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
# Score calculator
result = (correct/questions)*100
print(getpass.getuser() + "," + " you scored " + str(result) + "%")