Robotics & Artificial Intelligence
Write a function for checking the speed of drivers. This function should have one parameter: speed.
- If speed is less than 70, it should print "OK".
- Otherwise, for every 5 km above the speed limit (70), it should give the driver one demerit point. Calculate and print the total number of demerit points at the end. For example, if the speed is 80, it should print: "Demerit Points: 2".
- If the driver gets more than 12 demerit points, the function should print: "License suspended".
Python Functions
2 Likes
Answer
def check_speed(speed):
if speed < 70:
print("OK")
else:
points = (speed - 70) // 5
print("Demerit Points:", points)
if points > 12:
print("License suspended")
speed = int(input("Enter speed: "))
check_speed(speed)Output
Enter speed: 85
Demerit Points: 3
Enter speed: 60
OK
Enter speed: 140
Demerit Points: 14
License suspended
Answered By
3 Likes
Related Questions
Write a function that returns the greater of two numbers passed as arguments.
Write a function called ice_water that takes a number as input. Perform the following operations:
- If the number is divisible by 3, then it should return "ice".
- If it is divisible by 5, then it should return "water".
- If it is divisible by both 3 and 5, then it should return "icewater".
- Otherwise, it should return the same number.
Write a function that returns the sum of multiples of 3 and 5 between 0 and limit (parameter). For example, if the limit is 20, it should return the sum of 3, 5, 6, 9, 10, 12, 15, 18, 20.
What are the various parameter passing techniques?