Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Videos

Question
Book Icon
Chapter 9, Problem 14PE
Program Plan Intro

Program to displays a line to trace the walk

Program plan:

  • Import the required packages
  • In the “main()” function,
    • Generate a prompt to take the user input.
    • Create the object of “GraphWin()”.
    • Set the coordinates by calling the function “setCoords()”
    • A loop is initialized for “i” to be less than 5.
      • Call the function named “randWalk()”.
  • The function named “randWalk()” is defined and inside it,
    • Create the object of “Point()”.
    • Initialize a loop to get the x and y coordinates.
      • Store the x-coordinate value derived in x variable.
      • Store the y-coordinate value derived in y variable.
      • Call the function named “simOneStep()”.
      • Draw the line with the use of function “draw()”.
      • Create the object of “Line()”.
      • Draw the line with the use of function “draw()”.
      • Assign the value of “point1” to “point2”.
  • The function named “simOneStep()” is defined and inside it,
    • Calculate the angle between two axis and store in variable “angle”.
    • Calculate the position of x axis.
    • Calculate the position of y axis.
    • Create the object of “Point()”.
    • Return the value stored in variable “point”.
  • This code executes the main directly.

Blurred answer
Students have asked these similar questions
Write a graphical program to trace a random walk (see previous two prob-lems) in two dimensions. In this simulation you should allow the step to be taken in any direction. You can generate a random direction as an angleoff of the x axis. angle = random() * 2 * math.pi
Python programming: A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following: UP 5 DOWN B LEFT B RIGHT 2 i The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer. Example: If the following tuples are given as input to the program: UP 5 DOWN 3 LEFT 3 RIGHT 2 Then, the output of the program should be: 2 Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
In various applications, you are often asked to compute the mean and standard deviation of data. The mean is simply the average of the numbers. The standard deviation is a statistic that tells you how tightly all the various data are clustered around the mean in a set of data. For example, what is the average age of the students in a class? How close are the ages? If all the students are the same age, the deviation is 0. Write a program that prompts the user to enter any number of values into a double array, and then calculates and displays the mean and standard deviations of these numbers using the following formulas: mean)? 2i +x2 + .. + xn i=1 i=1 mean = deviation = п - 1
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
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