473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 1766
dwblas
626 Expert 512MB
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

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

Similar topics

1
by: Andrew Wilkinson | last post by:
Hi, First off I know that in almost all cases this would be a terrible thing to do, but this is an unusual case where this makes sense. Basically I have a procedure where you pass a string...
3
by: Yitzhak | last post by:
I am having "Permission denied" error while calling LogEvent method of WScript.Shell component. Basically, ASP page calls Windows Script Host Shell component to log events to the OS Application...
6
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
2
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect...
16
by: Saroj | last post by:
Is there an way for a function to know who called him ?
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
2
by: ENIZIN | last post by:
I am having an interesting problem where I am simply trying to put in country selection popup window on my site. When the user closes the window the popup should call the...
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
1
by: msraog | last post by:
Hi, Iam getting an error while calling a function which is declared in the external javascript file jsp file:- ------------------- <SCRIPT language='JavaScript1.1' src='includes/common.js>...
0
Malathi
by: Malathi | last post by:
Hi, In my windows application Im using a dll function. While calling this function it shows some dialog boxes and then output which is a perfect one as I needed. As its dll, Im unable to access...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.