Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. Creating a Tickets Sale Simulation
- Use the Queue class defined in part 1 of this lab to write a program to simulate the process of people buying tickets from a single ticket counter. Assume that:
- The simulatioin runs in increments on 1 minute (that is, each iteration of the simulation loop represents 1 minute of real time).
- It takes exactly 1 minute for a customer at the ticket counter to buy tickets --regardless of the quantity.
- At each minute, there is a 50% chance that one person joins the ticket line, a 30% chance that two people join the ticket line, and a 20% chance that three people join the ticket line.
- Each customer will buy a random number of tickets, ranging from 1 to 4. Ticket availability ultimately determines the maximun number of tickets a customer can buy.
- There is a total of 200 tickets for sell. The simulation should stop as soon as all tickets are sold.
- The pseudo code for the simulation is as follows:
- Create queue ticketLine
- Set variable minutes to zero
- Set variable tickets_left to 200
- WHILE there are tickets left for sale DO
- Add new customers to ticketLine (based on probabilities) [*]
- IF the ticketLine is not empty, THEN
- Get next customer from ticketLine queue
- IF the tickets neeeded by the customer is larger than the tickets left, THEN
- Customer can only buy the number of tickets left
- END IF
- Subtract from tickets_left the number of tickets needed by the customer.
- END IF
- Increase minutes by one
- Print the number of minutes, the queue and the number of tickets left
- END WHILE
- Print the number of customers left without tickets.
- Print the total number of minutes it took the simulation to run
- How do I "Add a new customers to ticketLine (based on probabilities)"?
- We are assuming that at each simulation minute, a number of customers will join the ticket line. This number depends on the probability distribution given above.
- One approach is the following:
- Draw a random number r between 0 and 1 (use random.random())
- IF r < 0.5 then
- Add an integer random number between 1 and 4 to the queue
- ELSE IF r < 0.8 then
- Draw two random numbers between 1 and 4 and add them to the queue
- ELSE
- Draw three random numbers between 1 and 4 and add them to the queue
- Save the test program as csc102_lab12_ticketssale.py. Save a transcript as csc102_lab12_ticketssale.txt
- [*] For each customer, the value added to ticketLine is the number of tickets that customer intends to buy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement