By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How to calculate GPA using 'while' and calling another function for calculation

P: 1
What I'm trying to do is to takes amount of subjets, then takes raw score accordingly, and return GPA and this function will call checkGradePoint during GPA calculation.
Expand|Select|Wrap|Line Numbers
  1. def checkGradePoint(raw):
  2. if raw>100:
  3.     score = "Error, raw score exceed max score" 
  4. elif raw>80:
  5.     score = "4"
  6. elif raw>70:
  7.     score = "3"
  8. elif raw>60:
  9.     score = "2"
  10. elif raw>50:
  11.     score = "1"
  12. elif raw>0:
  13.     score = "0"
  14. else:
  15.     score = "Error, raw score exceed min score"
  16.  
  17.  
  18.  
  19. def calGPA(n):
  20. ''' (int) -> float
  21. >>> calGPA(5)
  22. raw score: 55
  23. raw score: 56
  24. raw score: 59
  25. raw score: 57
  26. raw score: 61
  27. 1.2
  28. >>> calGPA(3)
  29. raw score: 74
  30. raw score: 82
  31. raw score: 51
  32. 2.67
  33. >>>
  34. '''
  35. for i in range(n):
  36.     y = input("score?")
  37. while n: 
  38.     totpoints = 0
  39.     totunits = 0
  40.     while n:  
  41.         grade = checkGradePoint(raw)
This is how far I can go what should I do next?
Sep 25 '15 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 613
Assuming GPA = grades_total/number_of_grades, you would either store the grades entered in a list, and then sum and divide by the length (number) of grades, or keep a running total of the grades as they are entered and a counter that counts the number of grades entered and then divide accordingly.
Sep 25 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.