Page 125 - Information_Practice_Fliipbook_Class11
P. 125
06 operator: operation to be performed (e.g., /)
07 ltOperand: left operand (e.g., 30)
08 rtOperand: right operand (e.g., 4)
09 Output: evaluation of expression: loperand operator roperand (e.g., 30/4)
10 '''
11 operator = input('Enter operator from {+, -, *, /, %, //, **}: ')
12 ltOperand = int(input('Enter left operand (integer): '))
13 rtOperand = int(input('Enter right operand: (integer): '))
14 if operator == '+':
15 result = ltOperand + rtOperand
16 elif operator == '-':
17 result = ltOperand - rtOperand
18 elif operator == '*':
19 result = ltOperand * rtOperand
20 elif operator == '/':
21 result = ltOperand / rtOperand
22 elif operator == '%':
23 result = ltOperand % rtOperand
24 elif operator == '//':
25 result = ltOperand // rtOperand
26 elif operator == '**':
27 result = ltOperand ** rtOperand
28 else:
29 result = '???: invalid operator'
30 print(ltOperand, operator, rtOperand, '=', result)
nepatlOuSpuSl1:
>>> Enter operator from {+, -, *, /, %, //, **}: **
>>> Enter left operand (integer): 3
>>> Enter right operand: (integer): 4
3 ** 4 = 81
nepatlOuSpuSl2:
>>> Enter operator from {+, -, *, /, %, //, **}: //
>>> Enter left operand (integer): 243
>>> Enter right operand: (integer): 12
243 // 12 = 20
Program 5.9 WriStlnlprogrnelShnSlcoepuSttlShtlrnStloflinStrttSlnccordinglSolShtlfoaaowinglSnbat:
Time Rate of Interest (in percent)
LtttlShnnl3lytnrt 4
BtSwttnl3l(incautivt)lnndl5lytnrt 6
ForlnaaloShtrlvnautt 8
TolwriStlnlprogrnel(Progrnel5.9)lSolcoepuStltiepatlinStrttSlforlShtlprincipnalneounSlnndlShtltetlptriodlinlytnrt,lShtl
rnStloflinStrttSlitlnppaicnbatlSolShtlnuebtrloflytnrtlforlwhichlShtleontylitldtpotiStd.l
Solution:
01 '''
02 Objective:
03 1. Accept the principal and time (in years) from the user
04 2. Determine the rate of interest (rate) as per rules:
05 nYears >= 5, @8%,
06 3 <= nYears <5, @6%, nYears < 3, @4%
07 3. Compute simple interest
08 '''
Conditonnal SnStetnSt 111

