link to my video [https://drive.google.com/file/d/1mrmpM83TNR7y9A21WwoHJs2LnJQcfXZT/view?usp=sharing]
import getpass
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgement of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Run the quiz
run_quiz()
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgement of a code segment include the origin or original author’s name?
import getpass
import unittest.mock
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print(user_responses)
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Tester function to validate quiz functionality
def test_quiz():
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "yes", "integer", "boolean", "false", "code segment."], 100.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33),
]
for i, (test_input, expected_score) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_score}%")
user_input = "\n".join(test_input)
input_mock = user_input + "\n" # Add a newline to simulate user pressing Enter
with unittest.mock.patch("builtins.input", side_effect=input_mock):
run_quiz()
print("\n" + "-" * 40)
if __name__ == "__main__":
test_quiz() # Run the tester function
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Run the quiz
run_quiz()
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
----------------------------------------
Test Case 2 - Expected Score: 33.33%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
----------------------------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_82601/1380101449.py in <module>
57 test_quiz() # Run the tester function
58 # Calculate the score as a percentage
---> 59 score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
60 percentage_score = (score / total_questions) * 100
61
NameError: name 'user_responses' is not defined
import getpass
from unittest import mock # Import mock from unittest module
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print("user responses"+ user_responses)
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Tester function to validate quiz functionality
def test_quiz():
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "yes", "integer", "boolean", "false", "code segment."], 100.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33),
]
for i, (test_input, expected_score) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_score}%")
user_input = "\n".join(test_input)
input_mock = user_input + "\n" # Add a newline to simulate user pressing Enter
with mock.patch("builtins.input", side_effect=input_mock):
run_quiz()
print("\n" + "-" * 40)
if __name__ == "__main__":
test_quiz() # Run the tester function
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_82601/2443809881.py in <module>
56
57 if __name__ == "__main__":
---> 58 test_quiz() # Run the tester function
/tmp/ipykernel_82601/2443809881.py in test_quiz()
52 input_mock = user_input + "\n" # Add a newline to simulate user pressing Enter
53 with mock.patch("builtins.input", side_effect=input_mock):
---> 54 run_quiz()
55 print("\n" + "-" * 40)
56
/tmp/ipykernel_82601/2443809881.py in run_quiz()
26 percentage_score = (score / total_questions) * 100
27
---> 28 print("user responses"+ user_responses)
29
30 print("\nUser Responses:")
TypeError: can only concatenate str (not "list") to str
import getpass
import unittest.mock
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print(user_responses)
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Tester function to validate quiz functionality
def test_quiz():
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "yes", "integer", "boolean", "false", "code segment."], 100.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33),
]
for i, (test_input, expected_score) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_score}%")
user_input = "\n".join(test_input)
input_mock = user_input + "\n" # Add a newline to simulate user pressing Enter
with unittest.mock.patch("builtins.input", side_effect=input_mock):
run_quiz()
print("\n" + "-" * 40)
if __name__ == "__main__":
test_quiz() # Run the tester function
# Calculate the score as a percentage
total_questions = len(quiz)
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(, quiz.values()))
percentage_score = (score / total_questions) * 100
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Run the quiz
run_quiz()
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
----------------------------------------
Test Case 2 - Expected Score: 33.33%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
----------------------------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_82601/3676203657.py in <module>
57 test_quiz() # Run the tester function
58 # Calculate the score as a percentage
---> 59 score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
60 percentage_score = (score / total_questions) * 100
61 print(score)
NameError: name 'user_responses' is not defined
import getpass
import unittest.mock
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print(user_responses)
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
return user_responses, percentage_score # Return user_responses and percentage_score to the caller
# Tester function to validate quiz functionality
def test_quiz():
user_responses = [] # Define user_responses within the function
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "yes", "integer", "boolean", "false", "code segment."], 100.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33),
]
for i, (test_input, expected_score) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_score}%")
user_input = "\n".join(test_input)
input_mock = user_input + "\n" # Add a newline to simulate user pressing Enter
with unittest.mock.patch("builtins.input", side_effect=input_mock):
user_responses, score = run_quiz() # Call run_quiz and store user responses and score
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
if __name__ == "__main__":
test_quiz() # Run the tester function
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
Test Case 2 - Expected Score: 33.33%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['c', 'o', 'l', 'l', 'a', 'b']
User Responses:
Question 1: c
Question 2: o
Question 3: l
Question 4: l
Question 5: a
Question 6: b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
Quiz completed!
eneter, you scored 0.00%.
User Inputs:
1. c
2. o
3. l
4. l
5. a
6. b
import getpass
import unittest.mock
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
print(user_responses)
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Tester function to validate quiz functionality
def test_quiz():
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "yes", "integer", "boolean", "false", "code segment."], 100.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33),
]
for i, (test_input, expected_score) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_score}%")
# Create a mock input object
input_mock = unittest.mock.Mock()
# Set the side effect of the mock input object to return the test input
input_mock.side_effect = test_input
# Patch the builtins.input function with the mock input object
with unittest.mock.patch("builtins.input", input_mock):
# Run the quiz function
run_quiz()
print("\n" + "-" * 40)
if __name__ == "__main__":
test_quiz() # Run the tester function
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['collaboration', 'yes', 'integer', 'boolean', 'false', 'code segment.']
User Responses:
Question 1: collaboration
Question 2: yes
Question 3: integer
Question 4: boolean
Question 5: false
Question 6: code segment.
Quiz completed!
eneter, you scored 100.00%.
User Inputs:
1. collaboration
2. yes
3. integer
4. boolean
5. false
6. code segment.
----------------------------------------
Test Case 2 - Expected Score: 33.33%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
['collaboration', 'no', 'integer', 'boolean', 'true', 'code']
User Responses:
Question 1: collaboration
Question 2: no
Question 3: integer
Question 4: boolean
Question 5: true
Question 6: code
Quiz completed!
eneter, you scored 50.00%.
User Inputs:
1. collaboration
2. no
3. integer
4. boolean
5. true
6. code
----------------------------------------
import getpass
import unittest.mock
# Define the quiz dictionary with questions as keys and answers as values
quiz = {
"Communication, consensus building, conflict resolution and negotiation is an example of ": "collaboration",
"Should the acknowledgment of a code segment include the origin or original author’s name?": "yes",
"The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age ": "integer",
"The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?": "boolean",
"True or False? Program development is usually a solo endeavor." : "false",
"A group of statements is called.." : "code segment."
}
# Function to administer the quiz
def run_quiz():
total_questions = len(quiz)
user_responses = []
#it will start i as 1. it will take the quiz and isolate the items and then it will store it in question. It will then print out the respective question and then it will append what you said into a list.
for i, (question, correct_answer) in enumerate(quiz.items(), start=1):
print(f"\nQuestion {i}: {question}")
user_answer = input("Your answer: ").strip().lower()
user_responses.append(user_answer)
# Calculate the score as a percentage
score = sum(user_answer == correct_answer for user_answer, correct_answer in zip(user_responses, quiz.values()))
percentage_score = (score / total_questions) * 100
#this code is used to show the question number and what answer was provided for that question. This is done by the enumerate function wheich is helpful especially in iterations to find the index of a variable.
#in this case, enumerate is used for i and coninues to add +1 every single time the for loop runs. The response variable will hold the users response for that certain question each time the funtion iterates.
print("\nUser Responses:")
for i, response in enumerate(user_responses, start=1):
print(f"Question {i}: {response}")
print(f"\nQuiz completed!\n{getpass.getuser()}, you scored {percentage_score:.2f}%.")
# Display user inputs as a list
print("\nUser Inputs:")
for i, response in enumerate(user_responses, start=1):
print(f"{i}. {response}")
# Calculate the percentage of questions answered correctly and incorrectly
correct_answers = 0
incorrect_answers = 0
for user_answer, correct_answer in zip(user_responses, quiz.values()):
if user_answer == correct_answer:
correct_answers += 1
else:
incorrect_answers += 1
percentage_correct = (correct_answers / total_questions) * 100
percentage_incorrect = (incorrect_answers / total_questions) * 100
#print(f"\nPercentage correct: {percentage_correct:.2f}%")
#print(f"Percentage incorrect: {percentage_incorrect:.2f}%")
# Tester function to validate quiz functionality
def test_quiz():
# Add test cases to validate quiz functionality
test_cases = [
(["collaboration", "no", "integer", "boolean", "false", "code segment."], 100.0, 100.0, 0.0),
(["collaboration", "no", "integer", "boolean", "true", "code"], 33.33, 33.33, 66.67),
]
for i, (test_input, expected_percentage_score, expected_percentage_correct, expected_percentage_incorrect) in enumerate(test_cases, start=1):
print(f"\nTest Case {i} - Expected Score: {expected_percentage_score}%")
# Create a mock input object
input_mock = unittest.mock.Mock()
# Set the side effect of the mock input object to return the test input
input_mock.side_effect = test_input
# Patch the builtins.input function with the mock input object
with unittest.mock.patch("builtins.input", input_mock):
# Run the quiz function
run_quiz()
print("\n" + "-" * 40)
if __name__ == "__main__":
test_quiz() # Run the tester function
Test Case 1 - Expected Score: 100.0%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
User Responses:
Question 1: collaboration
Question 2: no
Question 3: integer
Question 4: boolean
Question 5: false
Question 6: code segment.
Quiz completed!
eneter, you scored 83.33%.
User Inputs:
1. collaboration
2. no
3. integer
4. boolean
5. false
6. code segment.
----------------------------------------
Test Case 2 - Expected Score: 33.33%
Question 1: Communication, consensus building, conflict resolution and negotiation is an example of
Question 2: Should the acknowledgment of a code segment include the origin or original author’s name?
Question 3: The variable age is to be used to represent a person’s age, years. Which of the following is the most appropriate data type for age
Question 4: The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is the most appropriate data type for isOpen ?
Question 5: True or False? Program development is usually a solo endeavor.
Question 6: A group of statements is called..
User Responses:
Question 1: collaboration
Question 2: no
Question 3: integer
Question 4: boolean
Question 5: true
Question 6: code
Quiz completed!
eneter, you scored 50.00%.
User Inputs:
1. collaboration
2. no
3. integer
4. boolean
5. true
6. code
----------------------------------------