Arithmetic Operators in python
Operators Description Example Calculation Output
= assignment x = 10
== equality x == y Is x equal to y
-x negation x = -10 y = -x y == 10
x + y addition 10 + 11 21
x - y subtraction 10 - 11 - 1
x * y multiplication 10 * 11 110
x / y division 25 / 10 2.5
x // y division trunc 25 // 10 2
25// 10.0 2.0
x % y modulus 25 % 10 5 (remainder)
25 % 7 4 (remainder)
X ** y exponentiation 10 ** 2 100 (== 102 )
Suggested template PLEASE modify as needed : fee = 0.0 # initialize
f1 = 5.0 # table 1 fee
f2 = 4.0 # table 2 fee
f3 = 2.0 # table 3 fee m = int(input(" Please enter number of minutes parked...")) if (0 < m and m <= 60 ): #table 1 minutes # hrs = int(m/60) + 1 # FYI only fee = f1 print("Parking fee for ", m, " minutes is $", fee) # now for table 2 elif (m > 60 and m <= 300): # table 2 # calculations needed print('we are in table 2 fee is ', fee) elif ( m > 300): # table 3 #calculations needed print('we are in table 3 fee == ', fee) else: print("error negative minutes", m )
OUTPUT
Please enter number of minutes parked...195
we are in table 2 fee is 0.0
Algorithm :
Input: minutes parked
Output: Parking fee
Your program should ask the user for minutes parked, use the various functions/operators as needed to determine in which table 1, 2 3 the minutes falls into, compute and output the parking fee
Let m = minutes parked
fee = parking fee
Please make sure your code uses the constants: f1 f2 f3
Once you have determined your algorithm, try it for several of the minute examples provided in the tables above for accuracy
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== fee = 0.0 # initialize f1 = 5.0 # table 1 fee f2 = 4.0 # table 2 fee f3 = 2.0 # table 3 fee m = int(input(" Please enter number of minutes parked...")) if (0 <= m and m <= 60): # table 1 minutes # hrs = int(m/60) + 1 # FYI only fee = f1 print("Parking fee for ", m, " minutes is $", fee) # now for table 2 elif (m > 60 and m <= 300): # table 2 # calculations needed fee = f2 print('we are in table 2 fee is ', fee) elif (m > 300): # table 3 # calculations needed fee = f3 print('we are in table 3 fee == ', fee) else: print("Error: negative minutes", m,'entered')
==================================================================
Get Answers For Free
Most questions answered within 1 hours.