Answer to Question #178329 in Python for tas

Question #178329

Assume, it is the end of the semester and the students would like to know the GPA they achieved for the subjects they registered and sit for the final exam. You are going to develop a program that can calculate GPA for the students according to the grade they get and the subject credit hours. The point scale for the grade is shown below. Grade Point Scale A 4.0, A- 3.7 ,B+ 3.3, B 3.0, B- 2.7, C+ 2.3, C 2.0, C- 1.7, D+ 1.3, D 1.0, D- 0.7, F= 0 Note the formulae below to calculate the GPA. ๐บ๐‘ƒ๐ด = ๐’”๐’–๐’Ž ๐’๐’‡ (๐’”๐’–๐’ƒ๐’‹๐’†๐’„๐’• ๐’„๐’“๐’†๐’…๐’Š๐’• ๐‘ฅ ๐’ˆ๐’“๐’‚๐’…๐’† ๐’‘๐’๐’Š๐’๐’•) / ๐’•๐’๐’•๐’‚๐’ ๐’„๐’“๐’†๐’…๐’Š๐’• ๐’‚๐’•๐’•๐’†๐’Ž๐’‘๐’•๐’†๐’… Please make sure to apply the loop concept.ย 


1
Expert's answer
2021-04-07T09:47:30-0400
def main():
ย  ย  #Read number of subjectsย 
ย  ย  numberSubjects=int(input("How many subjects have you registered?: "))
ย  ย  sumGradePoint=0
ย  ย  totalCredits=0
ย  ย  for i in range(0,numberSubjects):
ย  ย  ย  ย  #Read grade
ย  ย  ย  ย  subjectGrade=input("Enter the grade [A , A-, B+, B, B-, C+, C, C-, D+, D, D-, F]: ")
ย  ย  ย  ย  #Read the subject credit hours
ย  ย  ย  ย  creditHours=int(input("Enter the subject credit hours: "))
ย  ย  ย  ย  gradePoint=getGradePoint(subjectGrade)
ย  ย  ย  ย  #calculate sum grade point
ย  ย  ย  ย  sumGradePoint+=creditHours*gradePoint
ย  ย  ย  ย  totalCredits+=creditHours
ย  ย  #calculate GPA
ย  ย  GPA=sumGradePoint/totalCredits
ย  ย  #Display GPA
ย  ย  print("GPA = "+"{:.2f}".format(GPA))


ย  ย ย 
# Get Grade Point Scale A 4.0, A- 3.7 ,B+ 3.3, B 3.0, B- 2.7, C+ 2.3,ย 
# C 2.0, C- 1.7, D+ 1.3, D 1.0, D- 0.7, F= 0
def getGradePoint(subjectGrade):
ย  ย  if subjectGrade.upper()=="A":
ย  ย  ย  ย  return 4.0
ย  ย  if subjectGrade.upper()=="A-":
ย  ย  ย  ย  return 3.7
ย  ย  if subjectGrade.upper()=="B+":
ย  ย  ย  ย  return 3.3
ย  ย  if subjectGrade.upper()=="B":
ย  ย  ย  ย  return 3.0
ย  ย  if subjectGrade.upper()=="B-":
ย  ย  ย  ย  return 2.7
ย  ย  if subjectGrade.upper()=="C+":
ย  ย  ย  ย  return 2.3
ย  ย  if subjectGrade.upper()=="C":
ย  ย  ย  ย  return 2.0
ย  ย  if subjectGrade.upper()=="C-":
ย  ย  ย  ย  return 1.7
ย  ย  if subjectGrade.upper()=="D+":
ย  ย  ย  ย  return 1.3
ย  ย  if subjectGrade.upper()=="D":
ย  ย  ย  ย  return 1.0
ย  ย  if subjectGrade.upper()=="D-":
ย  ย  ย  ย  return 0.7
ย  ย  return 0
ย  ย ย 
main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS