+ 5
Akkarawut 5105
The problem you have in your code is completely different to your original question.
However solution below using tuples and slicing via a boolean return of comparison operators
#Problem
#Do not use (if else)
#Write a program to calculate parking fees
'''
20 minutes free parking
1 hour 10 baht
2 hours later, the price is 20 baht/hour.
3 hours or more, 40 baht/hour
Fractions of minutes rounded up to hours.
(allowed to use "math.floor" and "math.ceil")
translated by Akkarawut 5105
'''
import math
time = int(input()) # in minutes
hrs = math.ceil(time/60)
rate = (hrs,4)[hrs >2]
fee = 0
for i in range(1,hrs+1):
fee += (0,rate *10)[time > 20]
print(("free",f'${fee}')[fee !=0])
+ 7
You have any source or something to show the full question?
+ 6
What you have tried so far?
+ 3
Mine yours doesn't understand.
+ 3
Akkarawut 5105
Are you sure it is not 0.25$ for 15 minutes.
Also is 7 minutes considered to be 15 minutes.
Is 16 minutes considered to be 30 minutes.
There is lots of missing info
+ 3
Akkarawut 5105
Ok!, thanks
What would be the cost for 67 minutes?
I am still trying to get my head around the concept
+ 2
Your question is not that clear reframe it well please
+ 1
- take time as input.
- set sum = 0
- set time to time - 20 minutes (because the first 20 minutes are free)
- set time to time - 1 hour and add price for first hour to sum
- set time to time - x hours and add price for x hours to sum
- and so on until time is <= 0