Question: hese pieces and run the experiment multiple times - - you're encouraged to recycle code from last week. As always, if you run into issues,

hese pieces and run the experiment multiple times -- you're encouraged to recycle code from last week. As always, if you run into issues, come to student hours!
rom random import random
Toss a coin that's been weighted with probability p for heads
lef tosscoin(p):r = random()
if r p:
return 'H'
else:
return 'T'
Toss coins until we get heads, and report the number of tries
This is one trial of the experiment that you'LL want to carry out
lef tosscount (p) :
count =0
# Toss a coin until we get heads
while True:
count +=1
toss =tossCoin(p)
# If heads, stop and return the count. Otherwise, Loop.
# The == operator is a comparison: it just checks if the
# toss was actually 'H' or not.
if toss =='H':
return count
This method tells you if a number is even or odd
lef isEven(n):
# The % operator divides by 2 and takes the remainder. Even numbers
# have a remainder of , odd number don't. This could also be coded
# in one line as .
if n%2=0 :
return True
else:
return False
hese pieces and run the experiment multiple times

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!