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 tosscoinp: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 :
count
# Toss a coin until we get heads
while True:
count
toss tossCoin
# 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:
# The operator divides by and takes the remainder. Even numbers
# have a remainder of odd number don't. This could also be coded
# in one line as
if :
return True
else:
return False
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
