I am trying to calculate the probability of an outcome with a hierarchical tree structure
The top is computer Computer A, the next 2 are Computer B & C, and the last 4 are Computer BD, BE, and CD, CE. I am trying to find the probability that if computer A gets infected with a virus what is the probability that B or C gets infected with a virus. And if B or C gets infected what is the probability that BD, BE, CD, CE gets infected with a virus
I want to run 100 trials to find the answer. I am new to doing probability on python. However here is the code I have so far:
import random, time
#prob that computers will get virus
CompA = 0.50
CompB = .25
CompC = .25
CompBD = .125
CompBE= .125
CompCD= .125
CompCE= .125
def generate():
x = random.random()
if x =< CompA: #Computer A has virus
prob_compa= sum(generate() for i in range(100)) #prob that Comp A has virus in a 100 rounds
print (prob_compa/100 + 'percent chance of getting virus')
try:
if CompB<.125:
prob_compa sum(generate() for i in range(100)) #prob that Comp B has virus in a 100 rounds
print (prob_compa/100 + 'percent chance of getting virus')
elif CompB<.125:
prob_compa= sum(generate() for i in range(100)) #prob that Comp C is sick in a 100 rounds
print (prob_compa/100 + 'percent chance of getting virus')
#I continue this method for the rest of the tree
Is there a better way and simpler way for me to get the results? random.uniform???