Question

Has to be written in Python 3 GPA calculator: Assume the user has a bunch of...

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:

  1. We will use these variables: units, grade, totalpoints, totalunits and GPA. Decide their type.
  2. 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.
  3. 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.
  4. A grade is legal if between 0 and 4. units is legal if between 1 and 5.
  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.
  6. If both grade and units are legal, we accumulate units*points into a totalpoints variable.
  7. We must also accumulate the totalunits variable.
  8. 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.
  9. Once the loop ends (after the loop) the GPA is the totalpoints divided by the totalunits.
  10. What do you need to do to show how many courses the user took? Write that code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Note: Brother while uploading on HomeworkLib, the indentations get changed. So, I request you to verify it with screenshots. Brother in case of any queries, just comment in box I would be very happy to assist all your queries.

import sys
Continue=True;
totalunits=0;
totalpoints=0;
while(Continue==True):
grade=int(input('Enter grade: '));
if(grade<0 or grade>4):
print('Error!');
sys.exit(0);
units=int(input('Enter the units of the course: '));
if(units<0 or units>4):
print('Error!');
Sys.exit(0);
totalunits=totalunits+units;
totalpoints=totalpoints+units*grade;
choice=input('Press y or enter yes tto continue: ');
if(choice[0]!='y' and choice[0]!='Y'):
Continue=False;
GPA=float(totalpoints)/float(totalunits);
print('The GPA IS ',GPA);

main.py 1 import sys 2 Continue-True 3 totalunits-0; 4 totalpoints-0; 5 while(Continue-True): 6 grade-int (input (Enter grad

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Has to be written in Python 3 GPA calculator: Assume the user has a bunch of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • GPA calculator: Assume the user has a bunch of courses they took, and need to calculate...

    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 create a textual menu that shows 3 choices. 1. Enter course grade and units. 2. Show GPA. 3....

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python 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 create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

  • write inputs and outputs declare variables promt user b. Modify the program written for Exercise 9a...

    write inputs and outputs declare variables promt user b. Modify the program written for Exercise 9a to determine wener e eReTeO evenly divisible by a user-specified value, with no remainder. That is, is it evenly divisible by 3, 7, 13, or any other user-specified value? 10. (Data processing) As a part-time student, you took two courses last term. Write, run, and test a C++ program that calculates and displays your grade point average (GPA) for the term. Your program should...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Write a Python program, with comments, to do the following:                        Ask the user to enter...

    Write a Python program, with comments, to do the following:                        Ask the user to enter a string with at least 7 characters. Assume user will enter a valid string. Assign the string to a variable str1 and print str1. In a loop do the following: Update the value of str1 so that the first character from the current value of str1 is removed and added to the end. Print the updated str1.       The loop should continue until updated...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • The following is solved using C++ in Vocareum: In this problem, you will be prompting a...

    The following is solved using C++ in Vocareum: In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA. This site: http://www.back2college.com/gpa.htm shows you how to calculate a GPA. Keep prompting the student if they want to add more courses. IMPORTANT NOTES! The course name is prompted for, but nothing is done with it. We are just using the grades A, B, C, D, and F so you...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers)...

    #include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers) { cin>>num; if(num < 0) { moreNumbers=false; } else { count = count+1; sum=sum+num; } } avg=sum/count; cout<<"Average grade:"<<avg<<endl; cout<<"How many grades were entered:"<<count<<endl; return 0; } Question: We need to add another loop to check input. Just like the input loop we already have, this one should use a boolean variable as a control. So, the logic could be something like this: Loop...

  • You will create a class to store information about a student�s courses and calculate their GPA....

    You will create a class to store information about a student�s courses and calculate their GPA. Your GPA is based on the class credits and your grade. Each letter grade is assigned a point value: A = 4 points B = 3 points C = 2 points D = 1 point An A in a 3 unit class is equivalent to 12 grade points (4 for the A times 3 unit class) A C in a 4 unit class is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT