Time for a Test!

Do you think you are ready to take a test about the vocabulary from CollegeBoard to help you become a better programmer?

Read the Code below to find out how to take the test, look at the outputs

def question_and_answer(prompt): # This part of the code defines the variable question_and_answer
    print("Question: " + prompt) # This line of code is printing Question and the prompt after it
    msg = input() # This line is setting the message to the user's input
    print ("Answer: " + msg) # The Code is printing the answer which is the user's message

import getpass, sys

def question_with_response(prompt): # Defining another variable
    print("Question: " + prompt)
    msg = input()
    return msg

questions = 5 # Defining the variable showing that there are 3 questions
correct = 0 # Before starting the quiz, this variable is set to 0, but as the user gets a question right, a point is added

print('Hello, ' + getpass.getuser() + " running " + sys.executable) # Finds the user's data and tells them what they are running
print("You will be asked " + str(questions) + " questions.") # Telling the user how many questions are on the quiz
question_and_answer("Are you ready to take a test?")

rsp = question_with_response("If you have two or more lines of code, what is this called?")
if rsp == "sequence": # This checks the user's response and checks if it is sequence, then it goes through an if statement to determine if the answer is right
    correct += 1 # The correct variable gets 1 point added
    print(rsp + " is the right answer, you have a score of " + str((correct / questions) * 100) + "%") # If the response is sequence, then this code will be outputted
else: # This takes the user's response and checks if it is sequence, if it is not it will go through an else statement
    print(rsp + " is incorrect, you have a score of " + str((correct / questions) * 100) + "%")

rsp2 = question_with_response("What is a key word commonly used in Python to define a function?")
if rsp2 == "def":
    correct += 1
    print(rsp2 + " is the right answer, you have a score of " + str((correct / questions) * 100) + "%")
else:
    print(rsp2 + " is incorrect, you have a score of " + str((correct / questions) * 100) + "%")

rsp3 = question_with_response("The three basics of a function are input, '____', and grouping commands?") # This is Question 3
if rsp3 == "output":
    correct += 1
    print(rsp3 + " is the right answer, you have a score of " + str((correct / questions) * 100) + "%")
else:
    print(rsp3 + " is incorrect, you have a score of " + str((correct / questions) * 100) + "%")

rsp4 = question_with_response("In programming, a '______' is used to define data patterns") # This is Question 4
if rsp4 == "dictionary":
    correct += 1
    print(rsp4 + " is the right answer, you have a score of " + str((correct / questions) * 100) + "%")
else:
    print(rsp4 + " is incorrect, you have a score of " + str((correct / questions) * 100) + "%")

rsp5 = question_with_response("What is it called when you group a sequence of commands? Hint: This is used very frequently") # This is Question 5
if rsp5 == "procedural abstraction":
    correct += 1
    print(rsp5 + " is the right answer, you have a score of " + str((correct / questions) * 100) + "%")
else:
    print(rsp5 + " is incorrect, you have a score of " + str((correct / questions) * 100) + "%")

print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
Hello, sunny running /bin/python3
You will be asked 5 questions.
Question: Are you ready to take a test?
Answer: yes
Question: If you have two or more lines of code, what is this called?
sequence is the right answer, you have a score of 20.0%
Question: What is a key word commonly used in Python to define a function?
def is the right answer, you have a score of 40.0%
Question: The three basics of a function are input, '____', and grouping commands?
output is the right answer, you have a score of 60.0%
Question: In programming, a '______' is used to define data patterns
dictionary is the right answer, you have a score of 80.0%
Question: What is it called when you group a sequence of commands? Hint: This is used very frequently
sequence is incorrect, you have a score of 80.0%
sunny you scored 4/5