Using python language
1- Write a function for checking the speed of drivers with 3
different speeds: 55, 90, 160.
If the return result is 0, it should print “Good”.
If the return is not zero but less then 12, it should print: ‘Too
fast“ if the return is greater than 70, then print “Your
license is suspended!”
2- Write a function that takes a series of numbers as parameters to
check if the driver is speeding up or slowing down. If the numbers
are increasing, return 1, if decreasing -1, if neither, return 0.
So, if you invoke the function with the parameters (25, 27, 34,
45), it will return 1; if (75, 67, 23), -1; but if (34, 60, 78, 69)
then 0. Staying the same would be increasing if the speed was
increasing before, decreasing if it was not. Hint: use *arg for
variable number of parameters.
I have written the program using PYTHON PROGRAMMING LANGUAGE.
Note : Question 1 is not so clear so please mention the question properly .
ANSWER for the question 2 :
OUTPUT :
CODE :
#function definition for SpeedRecognize
def SpeedRecognize(*arg):
if(list(arg) == sorted(list(arg),reverse = False)):
return 1#return 1
elif(list(arg) == sorted(list(arg),reverse = True)):
return -1#return -1
else:
0#return 0
#calling SpeedRecognize and storing the output in the variable called result
result = SpeedRecognize(34, 60, 78, 69)
if(result ==1) :
print("Speed is Up!!!")
elif(result == -1):
print("Speed is down!!!")
else:
print("Speed is neither Up nor Down!!!")
Thanks..
Get Answers For Free
Most questions answered within 1 hours.