# Run this cell to start.
import numpy as np
# Load the OKpy test library and tests.
from client.api.notebook import Notebook
ok = Notebook('lymphoma.ok')

#- Simulate 10000 trials of 17 patients
n_patients=18
p_cured= 0.9
counts = np.array([])
for i in np.arange(0,10000):
trial= np.random.uniform(0,2,n_patients)
cured= np.count_nonzero(trial <p_cured)
counts= np.append(counts, cured)
# Show the first five counts
counts[:5]

# Test you are on the right track.
_ = ok.grade('q_01_counts')

p_100 = (np.count_nonzero(counts == 17))/10000
# Show the value
p_100

# Test you are on the right track.
_ = ok.grade('q_02_p_100')

# This code is rather ugly, and needs editing to work correctly.
n_patients =17
p_cured=0.9
labs=4
lab_counts= np.array([])
for i in np.arange(0,labs):
trial= np.random.uniform(0,1,n_patients)
cured= np.count_nonzero(trial< p_cured)
lab_counts= np.append(lab_counts,cured)
lab_counts = np.zeros(4)
print(lab_counts[0], "patients cured in the first lab") # Simulate a count of patients cured in first lab.
print(lab_counts[1], "patients cured in the second lab") # Simulate a count of patients cured in second lab.
print(lab_counts[2], "patients cured in the third lab") # Simulate a count of patients cured in third lab.
print(lab_counts[3], "patients cured in the fourth lab") # Simulate a count of patients cured for fourth lab.
n_publications = np.count_nonzero(lab_counts == 17/labs)
print(n_publications, "proability to publish")

#- Simulate 10000 trials of four labs, each studying 17 patients.
publications = np.array ([])
trial= np.array([])
cured= np.array ([])
n_publications_2= np.array([])
for i in np.arange(0,10000):
lab_counts_2= np.array([])
for j in np.arange(0, labs):
trial= np.random.uniform(0,1,n_patients)
cured= np.count_nonzero(trial< p_cured)
lab_counts_2= np.append(lab_counts_2, cured)
n_publications_2= np.count_nonzero(lab_counts_2==n_patients)
publications= np.append(publications, n_publications_2)
# Show the first five publication counts
publications[:5]

# Test you are on the right track.
_ = ok.grade('q_04_publications')

p_at_least_one = (np.count_nonzero(publications >= 1)/10000)
# Show the value
p_at_least_one

# Test you are on the right track.
_ = ok.grade('q_05_p_at_least_one')

# For your convenience, you can run this cell to run all the tests at once!
import os
_ = [ok.grade(q[:-3]) for q in os.listdir("tests") if q.startswith('q')]