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

Python Programming concepts 12. Modity the previous pl 13 Write a program that g

ID: 3687666 • Letter: P

Question


Python Programming concepts

12. Modity the previous pl 13 Write a program that graphically plots a re that is, the line k the user to specif ically plots a regression line, that lection of points. First ask the on oints. First ask the user to find with the best fit through a collection of points. Bi er left corner of oints when the user dlick a small rectangle labeled "Done" in the lowerthe of in put, place a small re the window; the program will stop gathering points when theft cone inside that rectangle The regressi on line is the line with the following equation: where m= n2 z is the mean of the x-values, g is the mean of the y-values, and n is the number of points. As the user clicks on points, the program should draw them in the graphics window and keep track of the count of input values and the running sum of s, y, 2, and zy values. When the user clicks inside the "Done" rec: angle, the program then computes value of y (using the equations above corresponding to the r values at the left and right edges of the window t compute the endpoints of the regression line spanning the window the line is drawn, the program will pause for another mouse ick e window. After se click before closing the window and quitting.

Explanation / Answer

from graphics import * def regression(): # creating the window for the regression line win = GraphWin("Regression Line - Start Clicking!", 500, 500) win.setCoords(0.0, 0.0, 10.0, 10.0) rect = Rectangle(Point(0.5, 0.1), Point(2.5, 2.1)) rect.setFill("red") rect.draw(win) Text(rect.getCenter(), "Done").draw(win) message = Text(Point(5, 0.5), "Click in this screen") message.draw(win) points = [] # list of points n = 0 # count variable sumX = 0 sumY = 0 while True: p = win.getMouse() p.draw(win) # if user clicks in a red square it exits the loop and calculates the regression line if (p.getX() >= 0.5 and p.getX() = 0.1 and p.getY()