Академический Документы
Профессиональный Документы
Культура Документы
RAPORT
Lucrarea de laborator nr.3
la Testarea și verificarea produselor program
A efectuat: I. Ungureanu
Chișinău - 2017
A fair coin will be tossed until the first time it comes up heads. If this occurs on the jth toss
you are paid 2 to power j dollars. You are sure to win at least 2 dollars so you should be willing to
pay to play this game but how much? See if you can decide, by simulation, a reasonable amount
that you would be willing to pay, per game, if you will be allowed to make a large number of plays
of the game.
list_=[]
yaxis=[]
xaxis=[]
n=10000
purple='#8b475d'
profit1=0
def coin_game(nr_tosses):
list_=[]
counter=1
profit=0
for i in range(n):
while counter<nr_tosses:
profit=0
coin=random.randint(1,2)
if coin==1:
counter=counter+1
if coin==2: #heads
profit=2**counter
counter=1
break
list_.append(profit)
average_profit=sum(list_)/n
return average_profit
plt.plot(xaxis,yaxis,'.-', color='purple')
plt.xlabel("Number of tosses")
plt.ylabel("Average profit")
plt.grid(True)
plt.show
plt.savefig('problem1.png')
Input data:
nr_tosses – represents the number of tosses that will be simulated by the function
Output data:
average_profit – represents the sum of profits divided by the number of games
For simplicity n = 1
C = vertices – nodes + 2 = 20 – 16 + 2 = 6
Conclusion:
During this laboratory work, I worked with white box techniques. After testing the code, I observed
a little mistake in the implementation: in the while condition there should be a smaller or equal
sign (≤) instead of a smaller sign (<). It is because, from the condition we understand that 1 toss
is also possible and the sign did not allow the program to simulate only one coin toss.