Python Quiz
Creating, describing, and answering a quiz on python and its syntax
def question_and_answer(prompt): # defines question_and_answer
print("Question: " + prompt) # asks the question
msg = input() # the user's input/answer is taken
print("Answer: " + msg) # prints the user's input/answer
question_and_answer("Name the Python output command mentioned in this lesson?")
question_and_answer("If you see many lines of code in order, what would College Board call it?")
question_and_answer("Describe a keyword used in Python to define a function?")
import getpass, sys
def question_with_response(prompt): # defines question_and_answer
print("Question: " + prompt) # asks the question
msg = input() # the user's input/answer is taken
return msg # returns as string value
questions = 3 # total number of questions
correct = 0 # number that is initially correct (before any questions are answered)
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready to take a test?")
rsp = question_with_response("What command is used to include other functions that were previously developed?")
if rsp == "import": # establishing if/else statement; if user's input is "import"
print(rsp + " is correct!") # then it is correct
correct += 1 # one point is added to number correct score
else:
print(rsp + " is incorrect!") # if user's input is not "import," than user is incorrect
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)) # print's user's score
print ("Hello World") # image 1
msg = input("Enter a greeting: ") #image 2
print(msg)
import getpass, sys
def question_with_response(prompt): # defines question_and_answer
print("Question: " + prompt) # asks the question
msg = input() # the user's input/answer is taken
return msg # returns as string value
questions = 5 # total number of questions
correct = 0 # number that is initially correct (before any questions are answered)
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions!")
question_and_answer("Are you ready to take this fun test on Python syntax?")
rsp = question_with_response ("In image 1, Hello, World is what kind of text?")
if rsp == "static" or rsp == "output": # establishing if/else statement; if user's input is "static" or "output"
print(rsp + " is correct!") # then it is correct
correct += 1 # one point is added to number correct score
else:
print(rsp + " is incorrect :(") # if user's input is not "import," than user is incorrect
rsp = question_with_response("In image 1, what is the output?")
if rsp == "Hello World":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect :(")
rsp = question_with_response("In image 2, because the inputs and outputs can ______, the code is _______ ")
if rsp == "change and dynamic":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect :(")
rsp = question_with_response("The variable, msg, is then used as a _______ to the print command")
if rsp == "parameter":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect :(")
rsp = question_with_response("What is it grouping a sequence of commands, often used repeatedly, called?")
if rsp == "procedural abstraction":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect :(")
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions) + "!!") # print's user's score