Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
3rd Edition
ISBN: 9781590282779
Author: John Zelle
Publisher: Franklin Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 8, Problem 13PE
Expert Solution & Answer
Check Mark
Program Plan Intro

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()”.

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()

Sample Output

Output:

Screenshot of “Regression Line” window

Python Programming: An Introduction to Computer Science, Chapter 8, Problem 13PE , additional homework tip  1

After clicking “Done” button, the below window will appear

Screenshot of “Regression Line” window

Python Programming: An Introduction to Computer Science, Chapter 8, Problem 13PE , additional homework tip  2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Answer all of the questions with steps by step explanation to every question.
W Go Tools Window Help mac283_quiz3_fall2025.pdf Page 2 of 2 @ Q Q Û • ¨ ® - Qy Search X 00 01 11 10 0 1 1 1 0 1 1 1 1 1 A ABC 88% Problem 3. Draw the combinational circuit that directly implements the Boolean expression: F(x, y, z) = xyz + (y²+z) Problem 4. Find the truth table that describes the following circuit. y- z - X Problem 5. a) Describe how a decoder works and indicate typical inputs and outputs. b) How many inputs does a decoder have if it has 64 outputs? NOV 6 M tv♫ zoom
CPS 2390 Extra Credit Assignment For each problem, choose the best answer and explain how you arrived at your answer. (15 points each.) 1.If control is redirected to location x4444 after the execution of the following instructions, what should have been the relationship between R1 and R2 before these instructions were executed? Address Instruction x4400 1001100010111111 x4401 0001100100100001 x4402 0001100001000100 x4403 0000100001000000 A. R1 R2 (R1 was greater than R2) B. R1 R2 (R2 was greater than R1) C. R1 R2 (R1 and R2 were equal) = D. Cannot be determined with the given information. 2. If the value stored in RO is 5 at the end of the execution of the following instructions, what can be inferred about R5? Address x3000 Instruction 0101000000100000 x3001 0101111111100000 x3002 0001110111100001 x3003 0101100101000110 x3004 0000010000000001 x3005 0001000000100001 x3006 0001110110000110 x3007 0001111111100001 x3008 0001001111111000 x3009 0000100111111000 x300A 0101111111100000 A. The…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY