Heads or tails

- Import all random methods (eg import random)

- Generate a random number between 1-2

- Store the value in a variable called, 'rnd_value'

- If rnd_value equals 1, then output, 'heads' and if rnd_value equals 2, then output, 'tails'

- Use a variable called 'heads' assigned to 0, and a variable called, 'tails' assigned to 0

- Each time heads or tails is output, increment the variables heads to tails by 1

- Use a loop to repeat this process x1000, so that the variables heads/tails is being increment each time by 1

- After the loop is complete, then output the value of the variable heads and output the value of the variable tails.​

Respuesta :

import random

heads = 0

tails = 0

i = 0

while i < 1000:

   rnd_value = random.randint(1, 2)

   if rnd_value == 1:

       heads += 1

       print("heads")

   else:

       tails += 1

       print("tails")

   i += 1

print("Heads appeared {} times and tails appeared {} times".format(heads, tails))

I hope this helps!