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 12PE
Program Plan Intro

Random walk

Program Plan:

  • Import the header file.
  • Define the main method.
    • Call the “printIntro ()” method.
    • Get the input from the user.
    • Call the “avgSteps ()” method and store it in a variable.
    • Display the result.
  • Define the “printIntro ()” method.
    • Display the messages.
  • 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.
  • Call the main method.

Blurred answer
Students have asked these similar questions
A random walk is a random path most often represented as a random number that changes over time. In particular, one common random walk is that in which the starting state is 0 and in each iteration we either add 1 or subtract 1 from the current value with equal probability. That is, in the first step, the next value would be 1 with probability 0.5 and -1 with probability 0.5. Use R to generate a random walk with 100 values starting at value 0 and store the values in a vector called random_walk. This vector should have length 100.
You are given an instance of a problem where you have an n x n grid of squares. Each square can be unpainted or can have a hole, so you cannot go on the square with a hole. The objective is to paint all the squares that do not have a hole. You start in the square (0,0) which is unpainted. The actions you can do are: (1) paint the square you are on if it is not painted; (2) move, either vertically or horizontally, to an adjacent square inside the grid that is not painted and does not have a hole. a. Describe a state-space representation for the problem, specifying the state representation, the initial state, the goal condition, and the actions. b. Is the state space finite? Is it a tree or a graph? c. Propose a heuristic for the problem. Is your heuristics admissible or not? Explain briefly your answer
The bean machine is a device for statistical experiments. It consists of an upright board with evenly spaced nails (or pegs) in a triangular form, as shown in Figure 7.13 from our assigned textbook.Balls are dropped from the opening at the top of the board. Every time a ball hits a nail, it has a 50% chance of falling to the left or to the right. The piles of balls are accumulated in the slots at the bottom of the board.Write a program to simulate the bean machine that has 8 slots as shown in the figure. Your program should prompt the user to enter the number of balls to drop. Simulate the falling of each ball by printing its path. For example, the path for the ball in Figure 7.13(b) is LLRRLLR and the path for the ball in Figure 7.13(c) is RLRRLRR. Note that there are 7 levels of nails, so your path should be 7 letters (not 8).Create an array called slots. Each element in slots store the number of balls in a slot. Each ball falls into a slot via a path. The number of “R”s in a path is…
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