Description: A final project for CS50P in Python, designed to facilitate University students in a csv file students.csv
who are eligible to take a test, enabling them to do so, and upon completion, the program will automatically generate a comprehensive report results.csv
detailing the results.
The provided Python script is designed to simulate a quiz game for university students, involving arithmetic questions. The script utilizes command-line arguments and CSV files for input and output, allowing for flexibility and data persistence.
-
Main Functionality: The
main()
function acts as the central entry point. It orchestrates the flow of the program by ensuring correct command-line arguments, collecting student information, and initiating the quiz game. -
Command-line Argument Validation: The
check_commandla()
function verifies the presence and correctness of command-line arguments. It ensures that the script is invoked with exactly two CSV file paths, one for input and one for output. -
Student Information Retrieval and Quiz Initialization: The
play(last_name, initials, student_no)
function reads student details from the first CSV file provided as an argument. If the entered student information matches any entry, the function proceeds to simulate the quiz game. -
Score Calculation and Result Determination: Upon completion of the quiz game, the score is calculated based on the number of correct answers. The
percentage(score)
function determines whether the score meets the passing threshold (50%) and assigns a pass/fail status accordingly. -
Result Recording: The
creating_reports(last_name, initials, student_no, score, results)
function appends the student's results, including their name, initials, student number, score, and pass/fail status, to the second CSV file provided as an argument. -
Arithmetic Question Generation and Answer Validation: The script generates random arithmetic questions using the
generate_integer()
function. Each question involves two random integers and a randomly selected arithmetic operation. Thesimulate_round(x, y)
function prompts the user for the answer, validates it against the correct answer, and allows for a maximum of two attempts per question. -
Quiz Simulation: The
simulate_game()
function orchestrates the simulation of the quiz game by repeatedly callingsimulate_round()
for six rounds (representing six questions) and accumulating the score.
- Error Handling: The script incorporates robust error handling mechanisms to manage potential exceptions, such as missing CSV files or invalid input.
- Text-to-Speech Integration: Although commented out, the script includes code snippets for integrating text-to-speech functionality using the
pyttsx3
library. This feature, if activated, could provide auditory feedback of the quiz results.
In summary, the Python script offers a comprehensive solution for conducting a simulated quiz game for university students. It employs CSV files for storing student information and results, utilizes command-line arguments for configuration, and includes error handling mechanisms for robustness. The modular design of the script facilitates easy maintenance and extensibility, making it adaptable to various educational settings and scenarios.
Additionally, the script's flexibility allows for customization, such as adjusting pass/fail thresholds or expanding the question pool. Future enhancements could include support for more question types or integration with learning management systems for automated grading and reporting.
The provided test code verifies the correctness of specific functions within the project using the Pytest framework. Here's a breakdown:
-
test_check_commandla()
: This test ensures that thecheck_commandla()
function correctly raises aSystemExit
exception when invoked with insufficient command-line arguments. -
test_generate_integer()
: This test validates thepercentage()
function's behavior by checking its output against expected results for both passing and failing scores. -
test_simulate_round()
: This test verifies that thesimulate_round()
function raises aTypeError
when called without required arguments.
These tests provide a mechanism for automated validation of critical functionality within the project, ensuring reliability and correctness.