Let's walk through the software development process with a real-world example, creating a program that calculates the percentage score of an exam and determines the grade.
Step 1: Understanding the Problem
Alex, a student facing end-of-semester exams, wants a quick way to determine his final scores and grades from raw marks. The main issue is converting raw marks into a percentage and then assigning a letter grade.
Step 2: Defining What the Program Should Do
The program will accept two inputs: the student's score and the total possible score. The output will be the percentage score and the corresponding letter grade. The relationship between the inputs (student score and total score) and the output (percentage and grade) is defined by calculating the percentage and comparing it against a grading scale.
Step 3: Planning the Solution
Alex decides on a straightforward approach:
- Input: Prompt for the student's score and the total possible score.
- Process: Calculate the percentage (student score / total score * 100) and determine the letter grade based on the percentage.
- Output: Display the percentage and the letter grade.
Alex drafts the algorithm in pseudocode for clarity:
- Input student score and total possible score.
- Calculate percentage = (student score / total possible score) * 100
- Determine letter grade based on percentage ranges.
- Output percentage and letter grade.
Step 4: Writing the Code
Translating the pseudocode into Python, Alex writes the following program:
# exam_grade_calculator.py def main(): # Process phase # Determine letter grade # Output phase main() |
Step 5: Testing and Debugging
To ensure the program works correctly, Alex tests it with known values, such as:
Enter your exam score: 45 Enter total possible score: 50 Your percentage is 90.00%, which is a(n) A grade. |
These tests confirm the program accurately calculates the percentage and assigns the correct grade. With successful tests, the program is ready for use, streamlining Alex's exam grading process.
This simplified example once again underscores the importance of methodically progressing through the software development stages to create an effective, user-friendly program.