Exercise 4 DrunkPerson solution

$10.00

Original Work ?

Download Details:

  • Name: ex4.zip
  • Type: zip
  • Size: 48.44 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

Create a class DrunkPerson . Consider the situation
of drunk people trying to walk from the pub to the hotel. Start with no DrunkPerson s. At each time step
(loop iteration) create a new DrunkPerson at the pub
(position 0). Also, on each time step have every existing DrunkPerson take a step randomly forward (+1)
or backward (-1). Once any DrunkPerson reaches the
hotel (position 20), print out the current time and what
time that DrunkPerson left the pub, and end the program. Time in this project refers to the loop iteration.
You do not need to consider real world time.
Hints: To get a random of two numbers, first at
the top of your file use the line from random import
randrange then use randrange(2) to get a random number of 0 or 1. Just as with any other object,
use my_list.append(my_instance) to add a new instance of an object to a list. You will likely end up with
a loop inside of a loop to complete this assignment.
1