Hello.
First of all, I am not a native English speaker, so please forgive me for my bad English.
We received a homework in which we must write a program that flips a coin five times. Program then writes how many times heads has fallen.
(So, if it is... Heads, heads, tails, heads, tails... the program would print 3)
I wrote this code and I'm sure it should be working, but it only prints some random numbers (sometimes they are correct).
flip is a code we received at school and it simulates coin-flipping:
First of all, I am not a native English speaker, so please forgive me for my bad English.
We received a homework in which we must write a program that flips a coin five times. Program then writes how many times heads has fallen.
(So, if it is... Heads, heads, tails, heads, tails... the program would print 3)
I wrote this code and I'm sure it should be working, but it only prints some random numbers (sometimes they are correct).
Code:
from flip import flip
i = 0
s = 0
while i<5:
flip()
i = i +1
print (flip())
if flip() == "H":
s = s + 1
print (s)
flip is a code we received at school and it simulates coin-flipping:
Code:
import random
def flip():
return random.choice("HT")
Last edited:
