question
There are 1, 2, 3, 4 number card in a bag.
If you pick up 1, add one white ball into box_b.
If you pick up 2 or 3, add one white ball and one balck ball into box_b.
If you pick up 4, add two white balls and one black ball into box_b.
You must put the card back in your pocket every time you pull it out.
You have to do this 4 times.
When there are 8 balls in box_b, what is the probability that the number of black balls in the box is 2?
my code
import math
#흰공=0 검은공=1
box_b = list()
#조건부확률 = box_b 원소 개수 8개(=e)이면서 1이 2개(=f)일 확률 / e 확률
cnt_e = 0
cnt_ef = 0
for i in range(1, 5) :
if i == 1 :
box_b.append(0)
if i == 2 or 3 :
box_b.append([0, 1])
if i == 4 :
box_b.append([0, 0, 1])
for j in range(1, 5) :
if j == 1 :
box_b.append(0)
if j == 2 or 3 :
box_b.append([0, 1])
if j == 4 :
box_b.append([0, 0, 1])
for k in range(1, 5) :
if k == 1 :
box_b.append(0)
if k == 2 or 3 :
box_b.append([0, 1])
if k == 4 :
box_b.append([0, 0, 1])
for l in range(1, 5) :
if l == 1 :
box_b.append(0)
if l == 2 or 3 :
box_b.append([0, 1])
if l == 4 :
box_b.append([0, 0, 1])
print(box_b)
output
Output should be like [0, [0,1], [0,0,1], [0,1]], […], but it’s output is [0, [0,1], 0, [0,1], 0, [0,1], 0, [0,1] ….(very long list)…] [..]
what’s wrong with my code?
jinee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.