Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python, Big Lots wants you to conduct a simulation on customer buying a ce

ID: 3873519 • Letter: U

Question

Using Python,

Big Lots wants you to conduct a simulation on customer buying a certain product. This is called a MonteCarlo simulation.

Using the random() function, and given 100 customers, if the random number generated is <0.2 then a customer will Buy, and if greater than or equal to 0.2 then the customer will noBuy. Count and print out the number of buy and noBuy. Use a for-loop and a range function to indicate the 100 customers.

Hint: This is like counting a tail if   randomNumber >= 0.2 and a head otherwise

from random import random

buy = 0

noBuy = 0

for number in range (_, _):

        r = random()

        ?????????

Explanation / Answer

import random

buy = 0

noBuy = 0

for number in range (0,100):

r = random.uniform(0, 1)

if r<0.2:

buy = buy+1

else:

noBuy = noBuy+1

print("buy: " + str(buy))

print("nobuy: " + str(noBuy))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote