December 6th, 2013, 05:07 PM

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.
December 6th, 2013, 07:54 PM

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": #
if grade == "A" :
gradepnt= 4
elif grade == "B" :
gradepnt= 3
elif grade == "C" :
gradepnt= 2
elif grade == "D" :
gradepnt= 1
elif grade == "F" :
gradepnt= 0
else: ## added
print "No grade assignment made"
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.")
## added
coursenum = int(coursenum)
if 0 < coursenum < 6:
break
Last edited by dwblas; December 6th, 2013 at 08:08 PM.
December 7th, 2013, 12:26 PM

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
WEIGHTS weighted_average GRADES
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
Some testing of this code before you ask for help please.
Code:
$ python3 p.py
Please Enter The Student Name: dwl
What is the student's ID number?: 1234
Choose course(Example: CIS 101): Music108
Enter how much the Course Credit is: 0.5
Enter Grade Letter: A
Traceback (most recent call last):
File "p.py", line 47, in <module>
credit += crscreditamount
NameError: name 'credit' is not defined
You've got a long way to go on this project.
Last edited by b49P23TIvg; December 7th, 2013 at 12:31 PM.
[code]
Code tags[/code] are essential for python code and Makefiles!