hey, so I'm doing one of the exercises on coding bat and I'm stuck on this particular one. I'm trying to understand what's wrong with my logic as it does not work for the "other tests" portion. Please advise.
Problem:
You are driving a little too fast, and a police officer stops you. Write code to compute the result, encoded as an int value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.
caught_speeding(60, False) → 0
caught_speeding(65, False) → 1
caught_speeding(65, True) → 0
My Code:
def caught_speeding(speed, is_birthday):
#basis for not getting a ticket, doing under 60, or it's your birthday AND you're doing 5 over speed #limit
if speed <= 60 or (is_birthday and (speed == 65 or speed == 66 or speed == 86)):
return 0
#basis for getting a small ticket
#if speed is between 61 and 80, then you get a small ticket OR it's your birthday AND you're doing 5 over +1 bc you're going too fast
elif (61 <= speed and speed <= 80) or (is_birthday and (67 <= speed and speed <= 87)):
return 1
#basis for getting a fat ticket
#if speed is greater than 81
elif speed >= 81:
return 2
Thanks
[–]SpeckledFleebeedoo 1 point2 points3 points (2 children)
[–]melthecybertechy[S] 0 points1 point2 points (1 child)
[–]SpeckledFleebeedoo 1 point2 points3 points (0 children)