Page 214 - Computer Science Class 11 With Functions
P. 214
NtxS,latSlutluttlProgrnel9.4lSolcoepuStltiepatlinStrttSlforlnltuelofl4000lruptttlforltetlptriodtlofltixlytnrtlnndlSwolytnrt:
>>> Enter Principal Amount: 4000
>>> Enter time period in years: 6
Simple Interest= 960.0
>>> Enter Principal Amount: 4000
>>> Enter time period in years: 2
Simple Interest= 240.0
Program 9.5 WriStlnlfunctonlgrade(percentage)lShnSlcoepuSttlShtltSudtnS'tlgrndtlbnttdlonlShtltSudtnS't
ptrctnSngtlnndlShtlcuS-offlenrktltptcifitdlforlShnSlgrndt.l
percentage grade
>=75 A
>=60 B
>=50 C
>=33 D
<l33 F
Thtl functonl grade()l onayl nttdtl Sol chtckl inl ttqutnctl whtShtrl nl tSudtnS'tl ptrctnSngtl txcttdtl orl tqunatl Shtl
ptrctnSngtlrtquirtdlforlShtlgrndtlA, B, C, D. IflnltSudtnSlhntltcortdlnlptrctnSngtloflenrktlShnSldottlnoSlqunaifyl
hie/htrlforltvtnl'D'lgrndt,lht/thtlitlnwnrdtdlnnl'F'lgrndt,lindicntnglShnSlShtltSudtnSlhntlfniatd.lNoStlShnSlShtl
highlatvtaloflntttnglenkttlShtlfunctonlgrade()ltoetwhnSlhnrdlSolrtnd.
NoStlShnSlinlShtlfunctonlgrade(),lnnlif-tSnStetnSlitltncaottdlwiShinlnnoShtr if-tSnStetnS.lWhtnlnltSnStetnSl
tncaotttlnnoShtrltSnStetnS,lShtltncaottdltSnStetnSlitlcnaatdlnlnttStdltSnStetnS.lThtlfunctonlgrndt()liaautSrnSttlShnSl
ShtlnttStdltSnStetnSlcnnlngninltncaottlnnoShtrltSnStetnS,lnndltolon.lNtxS,latSlutlenktluttloflShtlfunctonlgrade()
inlProgrnel9.5lSolditpanylnltSudtnS'tlgrndt.ll
01 '''
02 Objective: To display a student's grade, based on his/her percentage
03 User input: percentage of marks obtained by the student
04 Output: Student's grade: A, B, C, D, or F
05 '''
06 #Approach: First write a function to compute student's grade
07 def grade(percentage):
08 '''
09 Objective: To compute a student's grade, based on his/her percentage
10 Input: percentage: percentage of marks obtained by the student
11 Return Value: grade (A, B, C, D, F) cutoffs 75, 60, 50, 33, respectively
12 '''
13 cutOffA = 75
14 cutOffB = 60
15 cutOffC = 50
16 cutOffD = 33
17 if percentage >= cutOffA:
18 return 'A'
19 else:
20 if percentage >= cutOffB:
21 return 'B'
22 else:
23 if percentage >= cutOffC:
24 return 'C'
25 else:
26 if percentage >= cutOffD:
27 return 'D'
28 else:
29 return 'F'
212 Touchpad Computer Science-XI

