Question
In this assignment you will write programs that use decision structures and can handle exceptions. [MO6.1, MO6.2, MO6.3] Directions Part A The speeding ticket fine
In this assignment you will write programs that use decision structures and can handle exceptions. [MO6.1, MO6.2, MO6.3]
Directions
Part A
The speeding ticket fine policy in Podunskville is $50 plus $5 for each mph over the speed limit plus a penalty of $200 for any speed over 90 mph.
- Write a program that accepts a speed limit and a clocked speed from the user, and either prints a message indicating the speed was legal or prints the amount of the fine, if the speed was illegal.
Part B(the program is below in python which needs to be modified)
- Modify the program you wrote for Programming Assignment 3 (Module 3) to handle the case when the line does not intersect the circle. You should use Pythons exception handling using try/except to catch the error and print out a customized error message.
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:59:38)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> from graphics import *
import math
rad = float(input('Radius of circle: ')) #input radius of circle
y = float(input('Y-intercept of line: ')) #input y-intercept of line
win = GraphWin('Circle', 600, 600) #window object of name 'Circle' and size 600 X 600
win.setCoords(-10, -10, 10, 10) #coordinates from (-10, -10) to (10, 10)
axis_x = Line(Point(-10, 0), Point(10, 0)) # drawing the X and Y axes
axis_y = Line(Point(0, -10), Point(0, 10))
t_x = Text(Point(9.5, -0.5), 'X')
t_y = Text(Point(-0.5, 9.5), 'Y')
axis_x.draw(win)
axis_y.draw(win)
t_x.draw(win)
t_y.draw(win)
circle = Circle(Point(0, 0), rad) #circle of given radius at (0, 0)
circle.draw(win)
line = Line(Point(-10, y), Point(10, y)) #horizontal line from (-10, y) to (10, y)
line.draw(win)
text = Text(Point(-7, 9.5), 'X-Value(s): ')
abs_y = abs(y)
if abs_y > rad: #no intersection if y > radius
pass
elif abs_y < rad: #two points of intersection if y < radius
x = (rad**2 - abs_y**2)**0.5 # r^2 = x^2 + y^2
x1 = Circle(Point(x, y), 0.125)
x1.setFill('red')
x2 = Circle(Point(-x, y), 0.125)
x2.setFill('red')
x1.draw(win)
x2.draw(win)
text.setText(text.getText() + str(round(x, 2)) + ' and ' + str(round(-x, 2)))
pass
else: #one point of intersection at (0, y) if y == radius
x = Circle(Point(0, y), 0.125)
x.setFill('red')
x.draw(win)
text.setText(text.getText() + '0')
text.draw(win)
win.getKey() #wait for key press
win.close() #close the window
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started