Answer to Question #312622 in Python for Chetan mirje

Question #312622

Write a function which prints the fine for breaking traffic rules. The function should take two parameters: Speed and Helmet.



Input Format



helmet = 0 (worn)



helmet = 1 (not worn)



speed = 60 km/hr



Constraints



Speed limit = 60 km/hr



Rules:



1. If speed > speed limit and helmet is worn, then fine = Rs 1000;



2. If speed <= speed limit and helmet is not worn, then fine = Rs 2000;



3. If speed > speed limit and helmet is not worn, then fine = Rs 5000;



4. If speed <= speed limit and helmet is worn, then print 'No Fine'



Output Format



Fine: Rs 1000



(or)



No Fine

1
Expert's answer
2022-03-16T10:23:25-0400
def traffic_rules(helmet, speed, speed_lim = 60):
    if(helmet == 0 and speed > speed_lim):
        print("Fine: Rs 1000")
        
    if(helmet == 1 and speed <= speed_lim):
        print("Fine: Rs 2000")
        
    if(helmet == 1 and speed > speed_lim):
        print("Fine: Rs 5000")
        
    if(helmet == 0 and speed <= speed_lim):
        print("No Fine")


traffic_rules(1, 61)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS