You can achieve your result in one of the following two ways.
First method:
This is straight forward solution.
Store all the coin one and coin two results in a list and return it to the calling method and check for the equality.
Second method:
You can return (actually yielding) back for each coin 1 and 2 value and check it in the calling method.
import random
def coin_one():
one = [random.randint(1, 100) for x in range(100)]
for x in one:
if x <= 50:
print('Heads')
#Use yield to return value and also continue method execution
yield 'Heads' #Add this line
else:
print('Tails')
yield 'Tails' #Add this line
def coin_two():
two = [random.randint(1, 100) for x in range(100)]
for x in two:
if x <= 50:
print('Heads')
yield 'Heads'
else:
print('Tails')
yield 'Tails'
coin_1_result = coin_one()
coin_2_result = coin_two()
for coin_1, coin_2 in zip(coin_1_result, coin_2_result):
if coin_1 == 'Heads' and coin_2 == 'Heads':
print('win')
else:
print('loss')
== operator is used to check for equality of two primitive values(int, string)
yield helps in building a list by sending each result to the calling function without returning or exiting the called method (coin_one() or coin_two()).
Here zip(a, b) allows two iterables (Example: list) to be iterate at the same time. i.e. It will return coin_1_result[0], coin_2_result[0] in first iteration and in second iteration it returns coin_1_result[1], coin_2_result[1] and so on.
Additionally, you can also notice that result of win or loss will be instantly printed after yielding first set of values from both functions.
Sample output:
Heads
Tails
loss
Heads
Heads
win