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

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 9, Problem 13PE
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 “avgTravel ()” method and store it in a variable.
    • Display the result by calling “printSummary ()” method.
  • Define the “printIntro ()” method.
    • Display the messages.
  • Define the “avgTravel ()” method.
    • Set the values
    • Iterate “i” till it reaches 1000
      • Call the “simNSteps ()” method
      • Calculate the “totBlocks”
        • Check “totBlocks” is equal to 0
          • Set the value
        • Otherwise, calculate the “avgDist”
        • Return the result.
  • Define “simNBlocks ()” method
    • Set the values
    • Iterate “i” till it reaches “n”
      • Calculate “x” value
        • Check “x” is greater than or equal to 0 and less than 1
          • Increment the “blockX” value
        • Check “x” is greater than or equal to 1 and less than 2
          • Decrement the “blockX” value.
        • Check “x” is greater than or equal to 2 and less than 3
          • Increment the “blockY” value
        • Otherwise, decrement the “blockY” value.
        • Return the result.
  • Define “printSummary ()” method
    • Display the result.
  • Call the main method.

Blurred answer
Students have asked these similar questions
A 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.
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.
Using Matlab. Monte Carlo methods are a class of computational methods that rely on repeated random sampling to compute their results. In this problem, you will use the Monte Carlo method to estimate the temperature at an arbitrary point in a uniform solid. Specifically, we will consider the solid object shown below. The temperatures of all surfaces are 500 des F with the exception of the two shaded surfaces, which are at 0 deg F. Inputs to the program should be: 1. The number of random walkers. 2. The (x,,2) coordinates of the point at which the temperature is to be estimated. 3. Plot interval (eg., you may want 1,000,000 random walkers in the simulation but may want to plot after every 10,000). Output from the program should be: 1. A graph of the estimated temperature, plotted according to the plot interval 2. Numerical value of the estimated temperature. USING MATLAB
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
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY