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.
- Discuss with appropriate examples the types of relationships in a database. Give one reference with your answer.arrow_forwardDetermine the velocity error constant (k,) for the system shown. + R(s)- K G(s) where: K=1.6 A(s+B) G(s) = as²+bs C(s) where: A 14, B =3, a =6. and b =10arrow_forward• Solve the problem (pls refer to the inserted image)arrow_forward
- Write .php file that saves car booking and displays feedback. There are 2 buttons, which are <Book it> <Select a date>. <Select a date> button gets an input from the user, start date and an end date. Book it button can be pressed only if the start date and ending date are chosen by the user. If successful, it books cars for specific dates, with bookings saved. Booking should be in the .json file which contains all the bookings, and have the following information: Start Date. End Date. User Email. Car ID. If the car is already booked for the selected period, a failure message should be displayed, along with a button to return to the homepage. In the booking.json file, if the Car ID and start date and end date matches, it fails Use AJAX: Save bookings and display feedback without page refresh, using a custom modal (not alert).arrow_forwardWrite .php file with the html that saves car booking and displays feedback. Booking should be in the .json file which contains all the bookings, and have the following information: Start Date. End Date. User Email. Car ID. There are 2 buttons, which are <Book it> <Select a date> Book it button can be pressed only if the start date and ending date are chosen by the user. If successful, book cars for specific dates, with bookings saved. If the car is already booked for the selected period, a failure message should be displayed, along with a button to return to the homepage. Use AJAX: Save bookings and display feedback without page refresh, using a custom modal (not alert). And then add an additional feature that only free dates are selectable (e.g., calendar view).arrow_forward• Solve the problem (pls refer to the inserted image) and create line graph.arrow_forward
- who started the world wide webarrow_forwardQuestion No 1: (Topic: Systems for collaboration and social business The information systems function in business) How does Porter's competitive forces model help companies develop competitive strategies using information systems? • List and describe four competitive strategies enabled by information systems that firms can pursue. • Describe how information systems can support each of these competitive strategies and give examples.arrow_forwardData communıcatıon digital data is transmitted via analog ASK and PSK are used together to increase the number of bits transmitted a)For m=8,suggest a solution and define signal elements , and then draw signals for the following sent data data = 0 1 0 1 1 0 0 0 1 0 1 1arrow_forward
- DatacommunicationData = 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0a) how many bıts can be detected and corrected by this coding why prove?b)what wıll be the decision of the reciever if it recieve the following codewords why?arrow_forwardpattern recognitionPCA algor'thmarrow_forwardConsider the following program: LOAD AC, IMMEDIATE(30) ADD AC, REGISTER(R1) STORE AC, MEMORY(20) Given that the value of R1 is 50, determine the value stored at memory address 20 after the program is executed. Provide an explanation to support your answer.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