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.
- Problem: A small company needs an interactive program to compute an employee’s paycheck. The payroll clerk will initially input the data, and given the input data, an employee's wage for the week should be displayed on the screen for the payroll check. The data for the employee includes the employee's hourly pay rate and the number of hours worked that week. Wage is equal to the employee's pay rate times the number of hours worked (up to 40 hours). If the employee worked more than 40 hours, wage is equal to the employee's pay rate times 40 hours plus 1½ times the employee's pay rate times the number of hours worked above 40. Instructions: Match the action at the left-side with the correct step number at the right-side (the attached picture). Note that it may be possible to group more than one related actions in the same logical step / process without altering the essence of the algorithm. In the program flow, input and checking of hourly pay rate should come before that of the number…arrow_forwardSlot Machine Simulation- I need to get answer in Pseudocode A slot machine is a gambling device that the user inserts money into and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images match, the user wins an amount of money, which the slot machine dispenses back to the user. Design a program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. Instead of displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars The program will select and display a word from this list three times. If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the program will inform the user that he or she has won two times the amount entered. If three of the words…arrow_forwardSee the sample outputs for more clarification. Project Specifications Input for this project: Values of the grid (row by row) Output for this project: Whether or not the grid is magic square Programmer's full name Project number Project due date Processing Requirements Use the following template to start your project: #include using namespace std; // Global constants // The number of rows in the array // The number of columns in the array // The value of the smallest number // The value of the largest number const int ROWS = 3; const int COLS = 3; const int MIN = 1; const int MAX = 9; // Function prototypes bool isMagicsquare(int arrayRow1[], int arrayRow2 [], int arrayRow3[], int size); bool checkRange (int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max); bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size); bool checkRowSum (int arrayrow1[], int arrayrow2[], int arrayrow3[], int size); bool checkColiSum(int arrayrow1[], int…arrow_forward
- 1. Write a program that lets the user guess whether a randomly generated integer would be even or odd. The program randomly generates an integer and divides it by 2. The integer is even if the remainder is 0, otherwise odd. The program prompts the user to enter a guess and reports whether the guess is correct or incorrect.arrow_forwardUsing C# in Microsoft Visual Studio create an application that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows:1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)2. The user selects his or her choice of rock, paper, or scissors. To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.3. The computer’s choice is displayed.4. A winner is selected according to the following rules:• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors…arrow_forwardDon't copy.arrow_forward
- The Game of Nim: The game of Nim starts with a random number of stones between 15 and 30. Two players alternate turns and on each turn may take either 1, 2, or 3 stones from the pile. The player forced to take the last stone loses. The computer player will make random choices during their turn. Your program must check to make sure that neither the computer nor the human player attempts to take 3 if there are only 1 or 2 stones left. The computer should only take 1 or 2 stones when 3 are left, and only 1 stone when 2 stones are left. Make sure you are using functions, importing random, and making it at around grade 10 coding levels, haha!arrow_forwardNumber Guessing Game. The program will generate a random number from 1 to 1000. The player will be given several chances to guess the number. The program gives a hint that the given number is lower or higher. If the player's guess is correct, give the player a single point. Tally the number of correct and wrong guesses that the player has made. After every round, display the tally (correct, wrong, and score) After a cycle the program will ask the user if he wants to continue playing. This is a console project. Below source code is my answer with the Question. Kindly check it sir/maam if i have the problem with the code. Thank you using System;using System.Collections.Generic;using System.Text;class Program{static void Main(string[] args){while (true){int randno = Newnum(1, 1001);int count = 1;while (true){Console.Write("Enter a number between 1 and 1000(0 to quit):");int input = Convert.ToInt32(Console.ReadLine());if (input == 0)return;else if (input <…arrow_forwardScissor, rock, paper Write a program called GameSRP.java that plays the popular scissor-rock-paper game where a scissor can cut paper, a rock kan nock a scissor and a paper can wrap a rock. The program asks the user for one of the options (1 for scissor, 2 for rock or 3 for paper) and then randomly picks one of them for the computer. It then presents if you or the computer won, or if it was a draw. If the user enters 0 the program will end and display the total score (number of wins for you and the computer and the draws). Here is a sample run: Scissor (1), rock (2), paper (3) or 0 to quit: 1 You lost, computer had rock! Scissor (1), rock (2), paper (3) or 0 to quit: 2 It's a draw! Scissor (1), rock (2), paper (3) or 0 to quit: 3 You won, computer had rock! Scissor (1), rock (2), paper (3) or 0 to quit: 1 You lost, computer had rock! Scissor (1), rock (2), paper (3) or 0 to quit: 2 It's a draw! Scissor (1), rock (2), paper (3) or 0 to quit: 3 You won, computer had rock! Scissor (1),…arrow_forward
- Slove by pythonarrow_forwardQuestion Write a program to determine the price for a portrait sitting. The price is determined by subjects in portraits, background chosen and sitting appointment day.The fee schedule is shown below. Fancy background and sitting appointment cost an extra 10 percent more than the base price. Subjects in Portrait Base Price 1 $100 2 $130 3 $150 4 $160 5 or more $165 Sample Output1: Enter the number of subjects in the portrait: 1 Do you want a fancy background (y/n)? y Do you want an appointment date (y/n)? y The price is: $120arrow_forward4) Roll the dice 2 Make a program that tests the probability of a certain score when rolling x dice. The user should be able to choose to roll eg 4 dice and test the probability of a selected score eg 11. The program should then do a number of simulations and answer how big the probability is for the selected score with as many dice selected. There must be error checks so that you cannot enter incorrect sums, for example, it is not possible to get the sum 3 if you roll 4 dice. TarningsKast2 How many dices do you want to throw? 11 Which number do you want the probability for? The probability the get the number 11 with 4 dices is 7.19% Calculatearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage