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))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.