Issue
This point of this game is to flip a coin 100 times and record either heads or tails. At the end of 100 flips, the program should print out the number of times it flipped heads and tails. The program is only printing heads when I run it and I feel that it is doing this by executing the first elif clause instead of the random.randint function.
Can anyone help complete this program??
import random
print ('Coin flip game')
start = input('Press enter to flip the coin')
coin_flip = random.randint(1, 2)
heads = int(1)
tails = int(2)
heads = int(heads)
tails - int(tails)
count = 0
while coin_flip:
count += 1
if count == 100:
break
elif coin_flip == 1:
print ('Heads')
elif coin_flip == 2:
print ('Tails')
Solution
try something like this:
import random
print("Welcome to the coin flipper!")
start = input('Press enter to flip the coin')
count = 0
while True:
coin_flip = random.randint(1,2)
count+=1
if count >100:
break
if coin_flip == 1:
print('Heads')
elif coin_flip == 2:
print("Tails")
this way each iteration of the loop the number will change since its inside the loop
also you dont need to assign all those variables that you dont even use later
and you should use while True:
for the loop
Answered By - Serial
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.