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