Python Practice/Quiz
The purpose of this entry is to capture the basics of Python in Jupyter.
This greeting code uses a simple print command.
print("Hello, please go ahead and try to don't fail the quiz!") # a greeting
The following code sequences provide a quiz about the basics of Python by using those basics:
import: Includes functions that were previously developed.
def: def/function/procedure; used for defining a function usually at the beginning of a sequence.
prompt: A message output to the user to describe the input requested.
msg: Short for message, used to capture input command.
Questions, answers and responses are defined using these basics.
Rsp and if/else commands will be used for evaluating scores.
import getpass ,sys
def question_and_answer(prompt): # defining the Q&A Function
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
questions = 3 # number of questions
correct = 0 # running score
print('Hello, ' + getpass.getuser() + " running " + sys.executable) # greetings
print("You will be asked " + str(questions) + " questions.") # the number of questions is presented here
question_and_answer("Are you ready to take a test?") # this question does not need a correct answer since it's not using an rsp variable
rsp = question_with_response("What command is used to include other functions that were previously developed?") # the following questions require a correct answer since they are using an rsp variable
if rsp == "import": # correct answer
print(rsp + " is correct!") # response to a correct answer
correct += 1 # gain points by answering correctly
else: # giving an incorrect answer
print(rsp + " is incorrect!") # response to an incorrect answer
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!")
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!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions)) # marks the end of the quiz
import getpass ,sys
questions = 3
correct = 0
rsp = question_with_response("What is the classic greetings in Python?")
if rsp == "Hello, World!":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What command activates the jupyter notebook input box?")
if rsp == "input":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Where is the false branch of code in an if command?")
if rsp == "else":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
The end of the quiz. Have a nice day!
Additional Resources:
These CollegeBoard videos are great for learning more about Python.