Advertisement
yukcheong

ReportCard,py

Nov 13th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def makeint(varname):
  2.     try:
  3.         int(varname)
  4.         return True
  5.     except ValueError:
  6.         return False
  7.  
  8.  
  9. def report_card():
  10.     classname=[]
  11.     grade=[]
  12.     n=1
  13.     subjectnum=raw_input('How many classes did you take? : ')
  14.     while makeint(subjectnum) !=True :
  15.         subjectnum=raw_input('Pls insert a valid numer : ')
  16.     else:
  17.         subjectnum2=int(subjectnum)
  18.         while subjectnum2 > 0 :
  19.             subjectname = raw_input('What is the name for class'+ str(n) +'? : ')
  20.             classname.append(subjectname)
  21.             subjectgrade=raw_input('What is  your grade for this class? : ')
  22.             while makeint(subjectgrade) != True :
  23.                 subjectgrade=raw_input('Pls insert a valid numer : ')
  24.             else:
  25.                 grade.append(subjectgrade)
  26.                 n += 1
  27.                 subjectnum2 -= 1
  28.         else:
  29.             pass
  30.     witch = len(classname)
  31.     while witch > 0:
  32.         print str(classname[len(classname)-witch]) + " -- " + str(grade[len(grade)-witch])
  33.         witch -= 1
  34.     else:
  35.         totalgrade=map(int,grade)
  36.         print "Overall GPA : " + str(float(sum(totalgrade))/float(len(totalgrade)))
  37.  
  38. report_card()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement