The speeding ticket tin policy in Potyomkin village s 6000 p

The speeding ticket tin. policy in Potyomkin village, s $60.00 plus $5.00 for each mph, over the speed limit. Moreover, the fine is doubled for any speed limit violation in a constructs zone. Furthermore, a penalty of $250.00 is added for any speed over 90 mph. Write a function, called speeding!), that takes three formal parameters: a speed limit (int). docked speed (int) and whether the speed limit violation took place in a construction zone or not (\"y\" or \"n\") as input, and either returns zero indicating the speed was legal or returns the amount of the fine, if the speed is illegal The caller of the function speeding!) in the test() function then prints a message using the format shown in the next problem. You must use if statements in your solution. Your speeding!) function must not print anything. Do not import external module in your solution. Write a test function, called test(), to test the speeding!) function with the following actual parameters and write a message accordingly: Call test() in your program and show the result. Examples of the correct output format include: Speeding violation fine for speed 35 in 50 mph zone (contraction = \"Y\'): $0.00 Speeding violation fine for speed 95 in 80 mph zone (construction= \'n\'): $385.00

Solution

def speeding( speed_limit, clocked_speed, in_construction_zone ):
   fine = 0.0;
   if( clocked_speed > speed_limit ):
       fine = 60 + (clocked_speed -speed_limit )*5;
       #doubled if in construction zone
       if (in_construction_zone==\'y\'):
           fine = fine*2;
       #if speed over 90, add penalty of 250
       if clocked_speed > 90:
           fine = fine + 250;

   return fine;

def test():
   speed_limit =   [50,80];
   clocked_speed = [35,95];
   construction_zone = [\'y\',\'n\'];
   for i in range(len(clocked_speed)):
       fine = speeding( speed_limit[i], clocked_speed[i], construction_zone[i] );
       print \'Speeding violation fine for speed\',clocked_speed[i],\'in\',speed_limit[i],\'mph zone (construction=\\\'\'+str(construction_zone[i])+\'\\\'): $\'+str(format(fine,\'.2f\'));

test();

 The speeding ticket tin. policy in Potyomkin village, s $60.00 plus $5.00 for each mph, over the speed limit. Moreover, the fine is doubled for any speed limit

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site