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_forwardIn the Raptor program Write a program 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 is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the computer’s choice yet.)2. The user enters his or her choice of “rock,” “paper,” or “scissors” at the keyboard.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 cuts paper.)• If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.)• If both players make the same choice, the…arrow_forwardAssignment Write a program that moves a forester unit and a desert corps unit to a given target location and prints the number of hours it took for each unit to reach the target. First, the user will give the starting X and Y positions of the forester unit as well as its base speed (all ints). Then, the starting X and Y positions of the desert corps unit as well as its base speed (all ints). Finally, the target X and Y positions (both ints) and the terrain type (std::string). Speeds are given as distance traveled in one full day (i.e., 24 hours) and is affected by the terrain type using a multiplier over the base speed. Also, after 1 full day, each unit rests for a certain number of hours. Speed multiplier and rest amount of each type of unit depending on the terrain type are as below. Speed Multiplier Rest Duration After 1 day Terrain type Forester Desert Corps Forester Desert Corps Forest 1.3 0.6 4 12 Desert 0.4 1.2 15 6 Hills 0.7 0.8 6 8 Others 1.0 0.8 8 6 After getting all this…arrow_forward
- Slot 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_forwardBirthday party At Lili's birthday party, there was a game arranged by Jojo as the host. That game is to distribute Y number of candy to X number of people where all the candy tastes sweet except for one last candy which tasted like rotten nuts. Candy distribution will be sequentially starting from position Z and if past the last position then the distribution of candy continues to the first position. Write down the person in which position will get the last candy. Input FormatThe first line of input is T, which is the number of test cases.The second row and the next number of T rows are X, Y, Z.X is the number of people to whom the candy will be distributed.Y is the number of candy available.Z is the starting position of the person to whom the candy will be distributed. Output FormatA string “Case #N: “ and a number representing the position of the person who got the last candy. Constraints1 ≤ T ≤ 1001 ≤ X, Y ≤ 1031 ≤ Z ≤ X Sample Input 43 4 13 5 24 2 24 5 2 Sample OutputCase #1: 1Case…arrow_forwardBirthday party At Lili's birthday party, there was a game arranged by Jojo as the host. That game is to distribute Y number of candy to X number of people where all the candy tastes sweet except for one last candy which tasted like rotten nuts. Candy distribution will be sequentially starting from position Z and if past the last position then the distribution of candy continues to the first position. Write down the person in which position will get the last candy. Input FormatThe first line of input is T, which is the number of test cases.The second row and the next number of T rows are X, Y, Z.X is the number of people to whom the candy will be distributed.Y is the number of candy available.Z is the starting position of the person to whom the candy will be distributed. Output FormatA string “Case #N: “ and a number representing the position of the person who got the last candy. Constraints? ≤ ? ≤ ???? ≤ ?, ? ≤ ???? ≤ ? ≤ X Sample Input 43 4 13 5 24 2 24 5 2 Sample OutputCase #1: 1Case…arrow_forward
- Using 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_forward1. 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_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
- This example creates a program to teach a first grade child how to learn subtractions. The program randomly generates two single- digit integers number1 and number2 with number1 > number2 and displays a question such as "What is 9 – 2?" to the student. After the student types the answer, the program displays a message to indicate whether the answer is correct.arrow_forwardGuess The Number Game: write a program that will ask the user to guess a secret numberrandomly generated by your program between 1-10. Player have 3 trials to guess the number.After each trial, you have to inform the user, either he/she has guessed it correctly or not, andthe remaining trials to guess the number. In each trial your program should generate a newrandom number. If user guess at least twice correctly, then shows the message, “you won by 2-1” and vice versa for losing.When game is over, ask the user to play again: If the user types "yes", the game start again.else stop the game.arrow_forwardThe 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_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr