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()”.
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()
Output:
Screenshot of output
Want to see more full solutions like this?
Chapter 7 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
- B A E H Figure 1 K Questions 1. List the shortest paths between all node pairs. Indicate the number of shortest paths that pass through each edge. Explain how this information helps determine edge betweenness. 2. Compute the edge betweenness for each configuration of DFS. 3. Remove the edge(s) with the highest betweenness and redraw the graph. Recompute the edge betweenness centrality for the new graph. Explain how the network structure changes after removing the edge. 4. Iteratively remove edges until at least two communities form. Provide step-by-step calculations for each removal. Explain how edge betweenness changes dynamically during the process. 5. How many communities do you detect in the final step? Compare the detected communities with the original graph structure. Discuss whether the Girvan- Newman algorithm successfully captures meaningful subgroups. 6. If you were to use degree centrality instead of edge betweenness for community detection, how would the results change?arrow_forwardUnit 1 Assignment 1 – Loops and Methods (25 points) Task: You are working for Kean University and given the task of building an Email Registration System. Your objective is to generate a Kean email ID and temporary password for every new user. The system will prompt for user information and generate corresponding credentials. You will develop a complete Java program that consists of the following modules: Instructions: 1. Main Method: ○ The main method should include a loop (of your choice) that asks for input from five users. For each user, you will prompt for their first name and last name and generate the email and password by calling two separate methods. Example о Enter your first name: Joe Enter your last name: Rowling 2.generateEmail() Method: This method will take the user's first and last name as parameters and return the corresponding Kean University email address. The format of the email is: • First letter of the first name (lowercase) + Full last name (lowercase) +…arrow_forwardI have attached my code, under I want you to show me how to enhance it and make it more cooler and better in graphics with following the instructions.arrow_forward
- After our initial deployment for our ML home based security system, the first steps we took to contribute further to the project, we conducted load testing, tested and optimize for low latency, and automated user onboarding. What should be next?arrow_forwardWhy investing in skills and technology is a critical factor in the financial management aspect of system projects.arrow_forwardwhy investing in skills and technology is a critical factor in the financial management aspect of systems projects.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning