![Python Programming: An Introduction to Computer Science, 3rd Ed.](https://www.bartleby.com/isbn_cover_images/9781590282755/9781590282755_largeCoverImage.gif)
Regression Line
Program plan:
- Import the header file.
- Define the “graphWin” method
- Create a window
- Set the coords
- Display the message on the window
- Call the “draw” method for set the point
- Call the “Line” method for draw the line
- Call the “draw” method for set the point
- Call the “Line” method for draw the line
- Call the “draw” method
- Call the “Rectangle” method
- Get the center position
- Set the “Done” text
- Call the “draw” method stop the program after clicking the “Done” text
- Accept the input from the user
- Set the list
- Make the condition true
- Get the mouse action
- Check the condition
- Break the loop
- Otherwise, store user points in an appended list
- Call the “draw” method
- Return the result
- Define the “average” method
- Set the values for the variables
- Iterate “i” until it reaches “allPoints” value
- Get the “x” and “y” value
- Calculate “sumX”, and “sumY”
- Increment the “count” value
- Calculate the “sumXiYi, “sqX”, “sumSqXi”, “SqY”, and sumSqYi” values
- Calculate the “a” and “b” values
- Return the values
- Define “main” method
- Display the text on the window
- Call the “average” method
- Set the values
- Call the “Line” method
- Call the “draw” method
- Get the mouse action
- Call the function “main()”.
![Check Mark](/static/check-mark.png)
Explanation of Solution
Program:
#import the required header files
from graphics import *
import math as m
#definition of "graphWin" method
def graphWin(Title):
#Create a graphics window
win = GraphWin(Title, 400, 400)
#set the coords
win.setCoords(-10, -10, 10, 10)
#tell user to select multiple locations on the screen to designate points
message = Text(Point(-3, 8), "Click to delineate points on the graph.")
#draw the point
message.draw(win)
#call the "Line" method
axisX = Line(Point(-10,0), Point(10,0))
#call the "draw" method
axisX.draw(win)
#call the "Line" method
axisY = Line(Point(0,10), Point(0,-10))
#call the "draw" method
axisY.draw(win)
#call the "Rectangle" method
r = Rectangle(Point(-9, -9), Point(-7,-8))
#call the "draw" method
r.draw(win)
#get the centre position
rCenter = r.getCenter()
#set the text
stopMouse = Text(rCenter, "Done")
#call the "draw" method
stopMouse.draw(win)
#accept input from user until <done> button is pressed
click = Point(0,0)
#set the list
allPoints = []
#check the condition
while True:
#get the mouse action
click = win.getMouse()
#check the condition
if ((-9 <= click.getX() <= -7) and (-9 <= click.getY() <= -8)):
#break the loop
break
#otherwise
else:
#store user points in an appended list
allPoints.append(click)
#call the "draw" method
click.draw(win)
#return the values
return allPoints, win
#definition of "average" method
def average(allPoints):
#set the values for the variables
sumX = 0
sumY = 0
count = 0
sumXiYi = 0
sumSqXi = 0
sumSqYi = 0
#iterate "i" until it reaches "allPoints" value
for i in allPoints:
#get the "x" and "y" value
x = i.getX()
y = i.getY()
#calculate the "sumX" value
sumX = sumX + x
#calculate the "sumY" value
sumY = sumY + y
#increment the value
count = count + 1
#calculate the "xy" value
xy = x * y
#calculate the "sumXiYi" value
sumXiYi = sumXiYi + xy
#calculate the "SqX" value
SqX = x * x
#calculate the "sumSqXi" value
sumSqXi = sumSqXi + SqX
#calculate the "SqY" value
SqY = y * y
#calculate the "sumSqYi" value
sumSqYi = sumSqYi + SqY
#calculate the "a" and "b" value
a = ((sumY * sumSqXi) - (sumX * sumXiYi)) / (count * (sumSqXi) - sumX ** 2)
b = ((count * sumXiYi) - (sumX * sumY)) / (count * (sumSqXi) - sumX ** 2)
#return the values
return a, b
#definition of "main" method
def main():
#get the text for the window
allPoints, win = graphWin("Regression Line")
#call the method
a, b = average(allPoints)
#set the values
x1 = -10
x2 = 10
#call the "Line" method
regressLine = Line(Point(x1, (a + b * x1)), Point(x2, (a + b * x2)))
#call the "draw" method
regressLine.draw(win)
#get the mouse action
win.getMouse()
#call the "main" method
main()
Output:
Screenshot of “Regression Line” window
After clicking “Done” button, the below window will appear
Screenshot of “Regression Line” window
Want to see more full solutions like this?
Chapter 8 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
- Which one of the 4 Entities mention in the diagram can have a recursive relationship? Order, Product, store, customer.arrow_forwardInheritance & Polymorphism (Ch11) There are 6 classes including Person, Student, Employee, Faculty, and Staff. 4. Problem Description: • • Design a class named Person and its two subclasses named student and Employee. • Make Faculty and Staff subclasses of Employee. • A person has a name, address, phone number, and e-mail address. • • • A person has a class status (freshman, sophomore, junior and senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString() method in each class to display the class name and the person's name. 4-1. Explain on how you would code this program. (1 point) 4-2. Implement the program. (2 point) 4-3. Explain your code. (2 point)arrow_forwardSuppose you buy an electronic device that you operate continuously. The device costs you $300 and carries a one-year warranty. The warranty states that if the device fails during its first year of use, you get a new device for no cost, and this new device carries exactly the same warranty. However, if it fails after the first year of use, the warranty is of no value. You plan to use this device for the next six years. Therefore, any time the device fails outside its warranty period, you will pay $300 for another device of the same kind. (We assume the price does not increase during the six-year period.) The time until failure for a device is gamma distributed with parameters α = 2 and β = 0.5. (This implies a mean of one year.) Use @RISK to simulate the six-year period. Include as outputs (1) your total cost, (2) the number of failures during the warranty period, and (3) the number of devices you own during the six-year period. Your expected total cost to the nearest $100 is _________,…arrow_forward
- Which one of the 4 Entities mention in the diagram can have a recursive relationship? If a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type (ID or Non-ID, also Justify why)?arrow_forwardPlease answer the JAVA OOP Programming Assignment scenario below: Patriot Ships is a new cruise line company which has a fleet of 10 cruise ships, each with a capacity of 300 passengers. To manage its operations efficiently, the company is looking for a program that can help track its fleet, manage bookings, and calculate revenue for each cruise. Each cruise is tracked by a Cruise Identifier (must be 5 characters long), cruise route (e.g. Miami to Nassau), and ticket price. The program should also track how many tickets have been sold for each cruise. Create an object-oriented solution with a menu that allows a user to select one of the following options: 1. Create Cruise – This option allows a user to create a new cruise by entering all necessary details (Cruise ID, route, ticket price). If the maximum number of cruises has already been created, display an error message. 2. Search Cruise – This option allows to search a cruise by the user provided cruise ID. 3. Remove Cruise – This op…arrow_forwardI need to know about the use and configuration of files and folders, and their attributes in Windows Server 2019.arrow_forward
- Southern Airline has 15 daily flights from Miami to New York. Each flight requires two pilots. Flights that do not have two pilots are canceled (passengers are transferred to other airlines). The average profit per flight is $6000. Because pilots get sick from time to time, the airline is considering a policy of keeping four *reserve pilots on standby to replace sick pilots. Such pilots would introduce an additional cost of $1800 per reserve pilot (whether they fly or not). The pilots on each flight are distinct and the likelihood of any pilot getting sick is independent of the likelihood of any other pilot getting sick. Southern believes that the probability of any given pilot getting sick is 0.15. A) Run a simulation of this situation with at least 1000 iterations and report the following for the present policy (no reserve pilots) and the proposed policy (four reserve pilots): The average daily utilization of the aircraft (percentage of total flights that fly) The…arrow_forwardWhy is JAVA OOP is really difficult to study?arrow_forwardMy daughter is a Girl Scout and it is time for our cookie sales. There are 15 neighbors nearby and she plans to visit every neighbor this evening. There is a 40% likelihood that someone will be home. If someone is home, there is an 85% likelihood that person will make a purchase. If a purchase is made, the revenue generated from the sale follows the Normal distribution with mean $18 and standard deviation $5. Using @RISK, simulate our door-to-door sales using at least 1000 iterations and report the expected revenue, the maximum revenue, and the average number of purchasers. What is the probability that the revenue will be greater than $120?arrow_forward
- Q4 For the network of Fig. 1.41: a- Determine re b- Find Aymid =VolVi =Vo/Vi c- Calculate Zi. d- Find Ay smid e-Determine fL, JLC, and fLE f-Determine the low cutoff frequency. g- Sketch the asymptotes of the Bode plot defined by the cutoff frequencies of part (e). h-Sketch the low-frequency response for the amplifier using the results of part (f). Ans: 28.48 2, -72.91, 2.455 KS2, -54.68, 103.4 Hz. 38.05 Hz. 235.79 Hz. 235.79 Hz. 14V 15.6ΚΩ 68kQ 0.47µF Vo 0.82 ΚΩ V₁ B-120 3.3kQ 0.47µF 10kQ 1.2k0 =20µF Z₁ Fig. 1.41 Circuit forarrow_forwarda. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 0 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuit in your report.arrow_forwardUsing XML, design a simple user interface for a fictional app. Your UI should include at least three different UI components (e.g., TextView, Button, EditText). Explain the purpose of each component in your design-you need to add screenshots of your work with your name as part of the code to appear on the interface-. Screenshot is needed.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
![Text book image](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)