Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
3rd Edition
ISBN: 9781590282779
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
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).
Your team was asked to program a self-driving car that reaches its destination with minimum travel time. Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given.   Answer:
The greatest common divisor of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid's algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: 1. Compute the remainder of dividing the larger number by the smaller number. 2. Replace the larger number with the smaller number and the smaller number with the remainder. 3. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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