### Thread: Needing help with gpa calculator (mostly done)

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2013
Posts
1
Rep Power
0

#### Needing help with gpa calculator (mostly done)

ok so im having some sort of trouble with this gpa calculator, i think i have the formula wrong, but im not so sure anymore, any input or advice would be wonderful.
2. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
May 2009
Posts
667
Rep Power
40
i think i have the formula wrong
What formula. We have no idea what you are trying to calculate.

The following doesn't make sense as the two parts are opposites. Also if you want to store more than one grade you will have to use a list to store them.
Code:
```while grade != "A" and grade != "B" and grade != "C" and grade != "D" and grade != "F":   #
This while loop will exit on an invalid number entered, < 0 or > 5 will still exit if you were converting to ints, but you are leaving as strings, "1", "2", etc., so anything greater then decimal 48 will be accepted, which includes colon and semicolon, and a zero input, "0" != 0. Some testing of this code before you ask for help please.
Code:
```while coursenum != 0:                                             #course number cannot equal 0
coursenum = input("How many courses are you taking?: ")   #input for number of courses
if int(coursenum) > 5:                                    #if more than 5 courses, it is invalid
print("That is not a valid Answer. Try again.")
elif int(coursenum) < 0:                                  #if less than 0, it is invalid
print("That is not a valid Answer. Try again.")

coursenum = int(coursenum)
if 0 < coursenum < 6:
break```
Last edited by dwblas; December 6th, 2013 at 07:08 PM.
3. I agree with the incorrectness of your GPA formula.

Correct formula for weighted average is ( the dot product of the weights with the values ) divided by the ( sum of weights )

Here's an example:

Concert Band. Weight: 1/2 credit. Grade: 4 A
Electrodynamics. Weight 3. Grade 1. D
Inorganic chemistry with lab. Weight 4. Grade 1. D
Latvian. Weight 3. Grade 2. C
Ultimate Frisbee. Weight 1. Grade 4. A

Semester GPA:
Code:
```((1/2 * 4  +  3 * 1  +  4 * 1  +  3 * 2  +  1 * 4 ))
--------------------------------------------------------------
(1/2  +  3  +  4  +  3  +  1)```
Which in executable Iverson notation we can express as
Code:
```   WEIGHTS =: 0.5 3 4 3 1
GRADES =: 4 1 1 2 4

sum =: +/
dot_product =: sum . *
At =: @:
left =: [
divided_by =: %
weighted_average =: dot_product divided_by sum At left

1.65217

weighted_average =: +/ .*%+/@:[  NB. In j I reduce the essence of the problem to 13 characters.  You're nowhere near completion in python.```
revealing a whopping D+ average.

Now let's try your program. I agree with
Originally Posted by dwblas
```\$ python3 p.py