Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 17PE
Program Plan Intro
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 “shape” and store the points
- The outline of the circle is set to “red” color.
- The circle is filled with “red” color.
- Draw the circle with the use of function “draw()”.
- Declare the required variables.
- Initialize a for loop to get the value of the points.
- Store the center of the circle in “c”.
- If the x-value is greater than 80 then
- Assign the value of “dx” as “-1”.
- If the x-value is less than -80
- Assign the value of “dx” as “1”.
- If the y-value is greater than 80 then
- Assign the value of “dy” as “-1”.
- If the y-value is less than -80
- Assign the value of “dy” as “1”.
- Use the function “sleep()” to slow the program.
- Move the circle to the resulting point.
- Call the function named “main()”
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that will print asterisks in the shape of a diamond. The height of the diamond will depend on the value entered by the user. That value MUST be greater than 0, and it MUST be odd. To make sure that the value is correct, you will validate the value once the user has entered it using a validation loop. Then you will print out a diamond in the pattern demonstrated in the sample execution. Remember that the height will vary based on the user input.
A square is divided into four smaller regions as shown in (a). If you throw a dart into the square one million times, what is the probability for the dart to fall into an odd-numbered region? Write a program to simulate the process and display the result.
Write a program that draws a graphic consisting of 50 rectangles with randomly generated sides
and 75 located randomly within a 300 by 300 stage. Hint: use a for loop and add each rectangle
anonymous rectangle into a pane You will need to set the fill color of each rectangle to TRANSE
the stroke to BLACK.
Chapter 7 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 7 - Prob. 1TFCh. 7 - Prob. 2TFCh. 7 - Prob. 3TFCh. 7 - Prob. 4TFCh. 7 - Prob. 5TFCh. 7 - Prob. 6TFCh. 7 - Prob. 7TFCh. 7 - Prob. 8TFCh. 7 - Prob. 9TFCh. 7 - Prob. 10TF
Ch. 7 - Prob. 1MCCh. 7 - Prob. 2MCCh. 7 - Prob. 3MCCh. 7 - Prob. 4MCCh. 7 - Prob. 5MCCh. 7 - Prob. 6MCCh. 7 - Prob. 7MCCh. 7 - Prob. 8MCCh. 7 - Prob. 9MCCh. 7 - Prob. 10MCCh. 7 - Prob. 1DCh. 7 - Prob. 2DCh. 7 - Prob. 3DCh. 7 - Prob. 1PECh. 7 - Prob. 2PECh. 7 - Prob. 3PECh. 7 - Prob. 4PECh. 7 - Prob. 5PECh. 7 - Prob. 6PECh. 7 - Prob. 7PECh. 7 - Prob. 8PECh. 7 - Prob. 9PECh. 7 - Prob. 10PECh. 7 - Prob. 11PECh. 7 - Prob. 12PECh. 7 - Prob. 13PECh. 7 - Prob. 14PECh. 7 - Prob. 15PECh. 7 - Prob. 16PECh. 7 - Prob. 17PECh. 7 - Prob. 18PE
Knowledge Booster
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
- Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3arrow_forwardWrite a program to create the following figure by using nested for loops. Please assign the number of lines as a class constant variable in order to change the size of the figure as in the sample figure. SEGMENT = 3 and HEIGHT = 4arrow_forwardA square is divided into four smaller regions as shown below in (a). If you throw a dart into the square 1,000,000 times, what is the probability for a dart to fall into an odd-numbered region? Write a program to simulate the process and display the result.arrow_forward
- Write a program that asks a user to input the height of triangle and draw a triangle that has the following pattern. Use nested loops for this problem. If the user enter height as 4 Then the triangle output is 1 1 2 1 2 3 1 2 3 4 We make the following assumptions • There is no space between the margin and first number in each row • There could be a space after the last number on every line • There is pne space between numbers on every line • There maybe a newline at the end of last line There is one test-case to check your code, there are two hidden testcases that tests correctness of your code 376584 2469arrow_forwardWrite a program that randomly chooses between three different colors for displaying text on the screen. Use a loop to display twenty lines of text, each with a randomly chosen color. The probabilities for each color are to be as follows: white = 30%, blue = 10%, green = 60%. Hint: generate a random integer between 0 and 9. If the resulting integer is in the range 0-2, choose white. If the integer equals 3, choose blue. If the integer is in the range 4-9, choose green.arrow_forwardWrite a program that will print the message “Computer Science is cool” 10 times. Use a while loop. Instead of printing 10 times, ask the user how many times the message should be printed. You will need to declare a variable to store the user’s response and use that variable to control the loop. Number each line in the output, and add a message at the end of the loop that says how many times the message was printed. So if the user enters 3, your program should print this: _____________________________________ 1 Computer Science is cool 2 Computer Science is cool 3 Computer Science is cool This message is printed 3 times. _____________________________________arrow_forward
- Write a program that will print the message “Computer Science is cool!!” 10 times. Use a while loop.2. Instead of printing 10 times, ask the user how many times the message should be printed. You will need to declare a variable to store the user’s response and use that variable to control the loop. 3. Number each line in the output, and add a message at the end of the loop that says how many times the message was printed. So if the user enters 3, your program should print this:arrow_forwardDevelop a solution that will calculate the average temperature, given a set of temperatures. The number of temperatures may differ from time to time. (Use a trip values to stop the processing of the loop.) Test the solution with the following 10 temperatures. 78 90 85 80 87 83 75 90 86 70arrow_forwardWrite a program that simulates car racing, as shown in Figure 9.29b–d. The car moves from left to right. When it reaches the right end, it restarts from the left and continues the same process. Let the user increase and decreasethe car’s speed by pressing the Up and Down arrow keys.arrow_forward
- Write a program to create the following figure by using nested for loops. Please assign the number of lines as a class constant variable in order to change the size of the figure as in the sample figure.arrow_forwardIt has been said that a monkey pushing keys a random on a typewriter could produce the works of Shakespeare, given enough time. you can simulate this by having a program select and display letters at random. count the number of letters typed until the program produces one of these two-letter words: at, is, he, we, up, or on. When one of these words is produced, stop the program and display the total number of letters typed. (hint: Choose a letter by selecting a random integer number between 1 and 26.)arrow_forwardWrite python code A skilled shooter tries to hit an apple with the Tomahawk arrow. At the same time, as he fires, the apple falls freely. If the velocity of the arrow is m/s, heights for both (apple and tomahawk) are m and horizontal distance between them is 400m, calculate the time when the arrow will hit the apple and visualize it as a simulation. Create an arrow and apple as defined.. Define a loop to update the speeds and positions of both (for both apple and arrow) including the effect of gravity. Plot the graph (Position : s Time).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY