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

Videos

Question
Book Icon
Chapter 7, Problem 16PE
Program Plan Intro

Program to displays the score with each click and the total score in series

Program plan:

  • Import the required packages
  • In the “main()” function,
    • Create the object of “GraphWin()”.
    • Set the coordinates by calling the function “setCoords()”
    • Create an object named “c” and store the points
    • The outline of the circle is set to “green4” color.
    • The circle is filled with “white” color.
    • The width of the circle is set with the use of function “setWidth()”.
    • Draw the circle with the use of function “draw()”.
    • Create an object named “c2” and store the points
    • The outline of the circle is set to “green4” color.
    • The circle is filled with “red” color.
    • The width of the circle is set with the use of function “setWidth()”.
    • Draw the circle with the use of function “draw()”.
    • Create an object named “c3” and store the points
    • The outline of the circle is set to “green4” color.
    • The circle is filled with “blue” color.
    • The width of the circle is set with the use of function “setWidth()”.
    • Draw the circle with the use of function “draw()”.
    • Create an object named “c4” and store the points
    • The outline of the circle is set to “green4” color.
    • The circle is filled with “black” color.
    • The width of the circle is set with the use of function “setWidth()”.
    • Draw the circle with the use of function “draw()”.
    • Create an object named “c5” and store the points
    • The outline of the circle is set to “green4” color.
    • The circle is filled with “white” color.
    • The width of the circle is set with the use of function “setWidth()”.
    • Draw the circle with the use of function “draw()”.
    • Initialize a for loop to get the value of the points.
      • Get the points where the mouse is clicked and store it in variable “arrow”.
      • Derive the x-coordinate with the use of “getX()” function.
      • Derive the x-coordinate with the use of “getY()” function.
      • Calculate the value derived out of the equation and store in “z”.
      • If the z-value is less than or equal to 5 and greater than 4 then,
        • “y” is assigned with “1”
        • “sum” is added with the value of “y”.
      • If the z-value is less than or equal to 4 and greater than 3 then,
        • “y” is assigned with “3”
        • “sum” is added with the value of “y”.
      • If the z-value is less than or equal to 3 and greater than 2 then,
        • “y” is assigned with “5”
        • “sum” is added with the value of “y”.
      • If the z-value is less than or equal to 2 and greater than 1 then,
        • “y” is assigned with “7”
        • “sum” is added with the value of “y”.
      • If the z-value is less than 1 then,
        • “y” is assigned with “9”
        • “sum” is added with the value of “y”.
      • otherwise,
        • “y” is assigned with “0”
        • print the output statement.
        • Print the value stored in “y” and “sum”.
  • Call the function “main()”.

Expert Solution & Answer
Check Mark
Program Description Answer

This program displays score achieved with each click in an archery board and also calculates and displays the sum of the entire series of outputs.

Explanation of Solution

Program:

#import the required packages

from graphics import *

import math as m

#define the main() function

def main():

    #declare the required variables

    win = GraphWin()

    #set the coordinates

    win.setCoords(-5, -5, 5, 5)

    #draw the circle with specified points

    c = Circle(Point(0,0), 5)

    #set the outline of the circle

    c.setOutline("green4")

    #fill the circle with the colour

    c.setFill("white")

    #set the width of the circle

    c.setWidth(1)

    #draw the circle

    c.draw(win)

    #draw the circle with specified points

    c2 = Circle(Point(0,0), 4)

    #set the outline of the circle

    c2.setOutline("green4")

    #fill the circle with the colour

    c2.setFill("red")

    #set the width of the circle

    c2.setWidth(1)

    #draw the circle

    c2.draw(win)

    #draw the circle with specified points

    c3 = Circle(Point(0,0), 3)

    #set the outline of the circle

    c3.setOutline("green4")

    #fill the circle with the colour

    c3.setFill("blue")

    #set the width of the circle

    c3.setWidth(1)

    #draw the circle

    c3.draw(win)

    #draw the circle with specified points

    c4 = Circle(Point(0,0), 2)

    #set the outline of the circle

    c4.setOutline("green4")

    #fill the circle with the colour

    c4.setFill("black")

    #set the width of the circle

    c4.setWidth(1)

    #draw the circle

    c4.draw(win)

    #draw the circle with specified points

    c5 = Circle(Point(0,0), 1)

    #set the outline of the circle

    c5.setOutline("green4")

    #fill the circle with the colour

    c5.setFill("white")

    #set the width of the circle

    c5.setWidth(1)

    #draw the circle

    c5.draw(win)

    #declare and initialize the variable

    sum = 0

    #initialize the loop for x less than 5

    for x in range (5):

        #get the locations where mouse is clicked

        arrow = win.getMouse()

        #stores the X coordinate

        x = arrow.getX()

        #stores the Y coordinate

        y = arrow.getY()

        #calculate and store the value

        z = m.sqrt(x ** 2 + y ** 2)

        #condition for z to be less than or equal to 5 and greater than 4

        if 5 >= z > 4:

            #declare the variable

            y = 1

            #calculate the value of sum

            sum = y + sum

        #condition for z to be less than or equal to 4 and greater than 3   

        elif 4 >= z > 3:

            #declare the variable

            y = 3

            #calculate the value of sum

            sum = y + sum

        #condition for z to be less than or equal to 3 and greater than 2      

        elif 3 >= z > 2:

            #declare the variable

            y = 5

            #calculate the value of sum

            sum = y + sum

        #condition for z to be less than or equal to 2 and greater than 1      

        elif 2 >= z > 1:

            #declare the variable

            y = 7

            #calculate the value of sum

            sum = y + sum

        #condition for z to be less than 1     

        elif 1 > z:

            #declare the variable

            y = 9

            #calculate the value of sum

            sum = y + sum

        #else statement   

        else:

           #declare the variable

            y = 0

            #print the statement

            print("You missed!")

        #print the statement

        print("Point: {0}    Total: {1}".format(y, sum))

#call the main() function

main()

Sample Output

Output:

Screenshot of output

Python Programming: An Introduction to Computer Science, 3rd Ed., Chapter 7, Problem 16PE

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
(C++) A robot is initially located at position (0, 0) in a grid [−5, 5] × [−5, 5]. The robot can move randomly in any of the directions: up, down, left, right. For each move, print the direction of the move and the current position of the robot. If the robot makes a circle, which means it moves back to the original place, print “Back to the origin!” to the console and stop the program. If it reaches the boundary of the grid, print “Hit the boundary!” to the console and stop the program.   A successful run of your code may look like:   Down (0,-1)   Down (0,-2)   Up (0,-1)   Left (-1,-1)   Left (-2,-1)   Up (-2,0)   Left (-3,0)   Left (-4,0)   Left (-5,0)   Hit the boundary!   or   Left (-1,0)   Down (-1,-1)   Right (0,-1)   Up (0,0)   Back to the origin!
Archery Scorer. Write a program that draws an archery target (see Pro-gramming Exercise 2 from Chapter 4) and allows the user to click five times to represent arrows shot at the target. Using five-band scoring, abulls-eye (yellow) is worth 9 points and each successive ring is worth 2fewer points down to 1 for white. The program should output a score foreach click and keep track of a running sum for the entire series.
C++ A robot is initially located at position (0; 0) in a grid [?5; 5]  [?5; 5]. The robot can move randomly in any of the directions: up, down, left, right. The robot can only move one step at a time. For each move, print the direction of the move and the current position of the robot. If the robot makes a circle, which means it moves back to the original place, print "Back to the origin!" to the console and stop the program. If it reaches the boundary of the grid, print \Hit the boundary!" to the console and stop the program. A successful run of your code may look like:Down (0,-1)Down (0,-2)Up (0,-1)Left (-1,-1)Left (-2,-1)Up (-2,0)Left (-3,0)Left (-4,0)Left (-5,0)Hit the boundary! or Left (-1,0)Down (-1,-1)Right (0,-1)Up (0,0)Back to the origin! About: This program is to give you practice using the control ow, the random number generator, and output formatting. You may use <iomanip> to format your output.ˆ ˆ You may NOT use #include "stdafx.h".
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Program to find HCF & LCM of two numbers in C | #6 Coding Bytes; Author: FACE Prep;https://www.youtube.com/watch?v=mZA3cdalYN4;License: Standard YouTube License, CC-BY