NCTU GPA calculator written in python2 Input Example

文章推薦指數: 80 %
投票人數:10人

NCTU GPA calculator written in python2 Input Example: 成績1,學分數1 成績2,學分數2 成績3,學分數3 ... - gpa_calc.py. Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. M157q/gpa_calc.py LastactiveDec29,2015 Star 1 Fork 1 Star Code Revisions 2 Stars 1 Forks 1 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP NCTUGPAcalculatorwritteninpython2InputExample:成績1,學分數1成績2,學分數2成績3,學分數3... Raw gpa_calc.py ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters #-*-coding:utf-8-*- deffind_gpa(grade): if100>=grade>=90: return[grade,'A+',4.3] elif89>=grade>=85: return[grade,'A',4.0] elif84>=grade>=80: return[grade,'A-',3.7] elif79>=grade>=77: return[grade,'B+',3.3] elif76>=grade>=73: return[grade,'B',3.0] elif72>=grade>=70: return[grade,'B-',2.7] elif69>=grade>=67: return[grade,'C+',2.3] elif66>=grade>=63: return[grade,'C',2.0] elif62>=grade>=60: return[grade,'C-',1.7] elif59>=grade>=50: return[grade,'D',1.0] elif49>=grade>=1: return[grade,'E',0.0] elifgradeis0: return[grade,'X',0.0] else: returnNone defmain(): #InputExample:成績1,學分數1成績2,學分數2成績3,學分數3... g=raw_input('Enteryourgrade:') g=g.strip().split() l=[] forxing: x=x.split(',') t=find_gpa(int(x[0])) iftisnotNone: t.append(x[1]) l.append(t) else: raiseBaseException('Youhavewronggrade.') avg=0.0 gpa=0.0 weights=0 forxinl: print('{0:4d}{1:2s}{2:1.1f}{3}'.format(x[0],x[1],x[2],x[3])) avg+=float(x[0])*int(x[3]) gpa+=float(x[2])*int(x[3]) weights+=int(x[3]) print('yourAVGgrade:{0}'.format(avg/weights)) print('yourGPA:{0}'.format(gpa/weights)) if__name__=="__main__": main() Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?