I have been asked to simulate whether a printer works after every hour in one day (i.e. 24 hours). If the printer works after the hour, then it has an 90% probability of working and 10% probability of being broken at the end of the next hour.
If broken, then it has 50% probability of working or being broken the next hour.
Assume random uniform distribution and that the first hour the printer is working.
My code in Python is below:
Chance = []
Status = []
for i in range(24):
Chance.append(random.uniform(0,1))
Chance[0] = 1
Chance
for i in Chance:
if i > 0.1:
Status.append('Working')
else:
Status.append('Broken')
Chance, Status
My problem is I can't simulate the the current event based on the previous event, i.e. if the previous event is broken how can I adjust the probability of the current event to 0.5.
Chance = np.random.uniform(size=24)
instead of the for loop. Second, why do you haveChance
on line 6 all by itself? – kevinkayaks