Question: Has to be written in Python 3 GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall
Has to be written in Python 3
GPA calculator:
Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work.
We will use a while loop and after getting the data of one course, we will ask if they have more courses to enter. If they answer 'Yes', or 'y' we continue. Anything else, we will stop and show the final GPA.
This requires us to write code that follows this logic:
- We will use these variables: units, grade, totalpoints, totalunits and GPA. Decide their type.
- We also need another variable, which will be used to decide to continue the loop or not. Let's call it Continue. It starts at True. Inside the loop, this variable will change to False based on asking the user.
- The condition for the while will be based on the Continue variable. If True, we enter the loop and ask the user for a grade, and number of units.
- A grade is legal if between 0 and 4. units is legal if between 1 and 5.
- If either grade or units are illegal, show an error message - do not perform steps 6 or 7.
- For better practice, write a function that returns True if the grade is legal, and False otherwise - this is optional.
- Do the same for units - this is optional.
- If both grade and units are legal, we accumulate units*points into a totalpoints variable.
- We must also accumulate the totalunits variable.
- Now we ask the user if they have more courses to enter. If they answer 'Yes', or 'y', we continue to loop. If not, we must stop the next iteration by assigning the Continue variable to False.
- Once the loop ends (after the loop) the GPA is the totalpoints divided by the totalunits.
- What do you need to do to show how many courses the user took? Write that code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
