문제
Many communities now have “radar” signs that tell drivers what their speed is, in the hope that they will slow down.
You will output a message for a “radar” sign.
The message will display information to a driver based on his/her speed according to the following table:
km/h over the limit | Fine |
1 to 20 | $100 |
21 to 30 | $270 |
31 or above | $500 |
https://www.acmicpc.net/problem/6763
입력
The input will be two integers.
The first line of input will be speed limit.
The second line of input will be the recorded speed of the car.
출력
If the driver is not speeding, the output should be:
Congratulations, you are within the speed limit!
If the driver is speeding, the output should be:
You are speeding and your fine is $F.
where F is the amount of the fine as described in the table above.
예제
# input
100
131
# output
You are speeding and your fine is $500.
# input
40
39
# output
Congratulations, you are within the speed limit!
문제 풀이
limit_speed = int(input())
current_speed = int(input())
gap = current_speed - limit_speed
if gap <= 0:
print('Congratulations, you are within the speed limit!')
elif 20 >= gap >= 1:
print('You are speeding and your fine is $100.')
elif 30 >= gap >= 21:
print('You are speeding and your fine is $270.')
else:
print('You are speeding and your fine is $500.')
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.