Question

In: Computer Science

Write a function for checking the speed of drivers. This function should have one parameter: speed....

Write a function for checking the speed of drivers. This function should have one parameter: speed.

1. If speed is less than 70, it should print “Ok”.

2. Otherwise, for every 5km above the speed limit (70), it should give the driver one demerit point and print the total number of demerit points. For example, if the speed is 80, it should print: "Points: 2". 3. If the driver gets more than 12 points, the function should print: “License suspended”

python language

Hide comments (1)

Solutions

Expert Solution

Python code:

#defining function to check speed
def speedCheck(speed):
    #checking if speed is less than 70
    if(speed<70):
        #priniting OK
        print("OK")
    else:
        #finding the number of points
        point=(speed-70)//5
        #printing it
        print("Points:",point)
        #checking if it is greater than 12
        if(point>12):
            #printing License suspended
            print("License suspended")
#calling speedCheck function for a sample value 150
speedCheck(150)


Screenshot:


Output:


Related Solutions

#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the...
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the #file and return the contents.# # # - If the contents of the file can be interpreted as # an integer, return the contents as an integer. # - Otherwise, if the contents of the file can be # interpreted as a float, return the contents as a # float. # - Otherwise, return the contents of the file as a # string. #...
using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you...
using python 1. #Write a function called multiply_by_index. multiply_by_index #should have one parameter, a list; you may assume every item #in the list will be an integer. multiply_by_index should #return a list where each number in the original list is #multipled by the index at which it appeared. # #For example: # #multiply_by_index([1, 2, 3, 4, 5]) -> [0, 2, 6, 12, 20] # #In the example above, the numbers 1, 2, 3, 4, and 5 appear #at indices 0,...
Please write the code in c++ Write a function with one input parameter that is a...
Please write the code in c++ Write a function with one input parameter that is a vector of strings. The function should count and return the number of strings in the vector that have either an 'x' or a 'z' character in them. For example, when the function is called, if the vector argument contains the 6 string values, "enter", "exit", "zebra", "tiger", "pizza", "zootaxy" the function should return a count of 4. ("exit", "zebra", "pizza", and "zootaxy" all have...
#Write a function called find_max_sales. find_max_sales will #have one parameter: a list of tuples. Each tuple...
#Write a function called find_max_sales. find_max_sales will #have one parameter: a list of tuples. Each tuple in the #list will have two items: a string and an integer. The #string will represent the name of a movie, and the integer #will represent that movie's total ticket sales (in millions #of dollars). # #The function should return the movie from the list that #had the most sales. Return only the movie name, not the #full tuple. #Below are some lines of...
python3 (3a) Write a function, frequent, with one parameter, psw, a string. If psw is in...
python3 (3a) Write a function, frequent, with one parameter, psw, a string. If psw is in a list of frequently used passwords ['password', '12345', 'qwerty', 'letmein', 'trustno1', '000000', 'passw0rd'], frequent should return False; otherwise, return True. Be sure to include at least three good test cases in the docstring. (3b) Password Protection SecuriCorp has recently been the victim of a number of security breaches. Internal analysis has determined that employees use simple passwords that are too easy to guess. You...
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be...
Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be passed in on the stack. The answer should be returned in eax. The subroutine should not disturb any registers except eax, ecx, and edx. (Save any registers on the stack and restore them before exiting the subroutine.) Upon entry to the subroutine, push ebp, etc., to access the parameter.
When a function can take another function as a parameter, how can type-checking occur? (Programming languages)
When a function can take another function as a parameter, how can type-checking occur? (Programming languages)
Write a function pretty_print, which takes one parameter that can be any type of namedtuple. It...
Write a function pretty_print, which takes one parameter that can be any type of namedtuple. It "pretty prints" the contents of the namedtuple, including both the names of its fields and their values. This is subject to a few rules. Each field and its value are displayed on one line, with the name of the field appearing first, followed by a colon and a space, followed by the value of the field converted to a string. The fields should be...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an...
solve with python 3.8 please 1,Write a function called make_squares_coordinate_pair that has one parameter - an int. The function should return a tuple containing that int and its square. Suppose you were to call your function like this: print(make_squares_coordinate_pair(5)) This should output: (5, 25) Your function MUST be called make_squares_coordinate_pair. You can write code in the main part of your program to test your function, but when you submit, your code must ONLY have the function definition! 2, Write a...
Write a function which takes one parameter int num, and prints out a countdown timer with...
Write a function which takes one parameter int num, and prints out a countdown timer with minutes and seconds separated by a colon (:). It should print out one line for each second elapsed and then pause one second before printing out the next line. A few things to note: - You can assume that calling the function usleep(1000000) makes the program pause for one second - It should count down from num minutes:zero seconds to zero minutes:zero seconds -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT