Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Chapter 7 from the book question number 6. 6. The speeding ticket fine po

ID: 3605844 • Letter: P

Question

Python Chapter 7 from the book question number 6.

6. The speeding ticket fine policy in Podunksville is $50 plus $5 for each mph over the limit plus a penalty of $200 for any speed over 90 mph. Write a program that accepts a speed limit and a clocked speed and either prints a message indicating the speed was legal or prints the amount of the fine, if the speed is illegal.

def speedtest(speedlimit,clockedspeed) def speedtest2(speedlimit,clockedspeed) if(speedlimit)sclockedspeed) : if(speedlimit»-clockedspeed) print("The speed was within the legal speedlimit." print("The speed was within the legal speedlimit." else: elif(clockspeed>90) print("The speed was over the legal speedlimit." fine = 50 + 5"((clockedspeed-speedlimit)//5) if clockedspeed90: print("The speed was over the legal speedlimit." fine = 50 + 5"((clockedspeed-speedlimit)//5) +200 print("The fine will be $",fine) fine +200 else: print("The fine will be S",fine) print( The speed was over the legal speedlimit.") fine - 50 5*(Cclockedspeed-speedlimit)//s) print"The fine will be S",fine) Look at these two solutions. Which one uses nested decisions: speedtest or speedtest2? If the speed is 50, how many condition checks does the computer make in speedtest? in speedtest2?

Explanation / Answer

Hi,
there are multiple questions in this, please post others as separate questions as its against chegg policy to answere more than 1 in any given answer
1.
Nested decisions are the ones in which you have an if/else inside and if/else block, so in the given solutions, speedtest uses nested decisions in the else part, we have one more if,
Number of comparisons for speed=50, assuming speedlimit as 40, as not given
1.speedtest- First comparison would be if 40>=50 and then second comparison would be if 50>=90
2.speedtest2- In this, we used elif so the first comparison is if 40>=50 and next it will come to elif which does the comparison of if 50>=90

Thumbs up if this was helpful, otherwise let me know in comments