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 11, Problem 18PE
Program Plan Intro

Random walk

Program Plan:

  • Import the header file.
  • Define the “avgSteps ()” method.
    • Set the value
    • Iterate “i” till it reaches 1000
      • Call the “simNSteps ()” method
      • Calculate the “totTravel”
    • Check “totTravel” is equal to 0
      • Set the value
    • Otherwise, calculate the “avgTravel”
    • Return the result.
  • Define “simNSteps ()” method
    • Set the value
    • Iterate “i” till it reaches “n”
      • Calculate “x” value
    • Check “x” is greater than 0
      • Increment the “steps” value
    • Check “x” is less than 0
      • Decrement the “steps” value
    • Otherwise, set the value
    • Return the result.
  • Define the “printIntro ()” method.
    • Display the messages.
  • Define the main method.
    • Call the “printIntro ()” method.
    • Get the input from the user.
    • Set the array
    • Iterate “i” until it reaches “n + 1”
      • Append the values
    • Set the value
    • Check “steps” is less than “n” and greater than 0
      • Calculate the “x” value
      • Check “x” is greater than 0
        • Increment the “steps”
        • Increment the “squares”
          • Check “x” is less than 0
            • Decrement the “steps”
            • Decrement the “squares”
          • Otherwise, set the value
    • Iterate “i” until it reaches “squares”
      • Print the output.
  • Call the main method.

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
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.
Coupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of objects repeatedly and determine how many picks are needed for all the objects to be picked at least once. A variation of the problem is to pick cards from a shuffled deck of 52 cards repeatedly and find out how many picks are needed before you see one of each suit. Assume a picked card is placed back in the deck before picking another. Write a program to simulate the number of picks needed to get four cards from each suit and display the four cards picked (it is possible that a card may be picked twice).
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY