Jan-05-2020, 06:58 PM
Hey guys,
this exercise is confusing me: The idea here is to create a program, which simulates coin flips by randomly selecting 0 (Tails) or 1 (Heads) and printing out the result. When working correctly, the program prints out something like this:

Obviously, as the program applies random activities, it may give any combination of five heads or tails. For example, running the program a second time resulted in this:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is my code:

It seems to me that the first automatic input is supposed to generate only one flip, and then for the second time, it generates 5, but I don't know how to do that. Perhaps it's actually supposed to always generate 5 and I'm doing something wrong in my code.
Thanks in advance!
this exercise is confusing me: The idea here is to create a program, which simulates coin flips by randomly selecting 0 (Tails) or 1 (Heads) and printing out the result. When working correctly, the program prints out something like this:

Obviously, as the program applies random activities, it may give any combination of five heads or tails. For example, running the program a second time resulted in this:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is my code:
import random numbers = [] #picks 5 random numbers from 0 to 1 while True: if len(numbers) == 5: break pick = random.randint(0,1) numbers.append(pick) #0 == Tails; 1 == Heads for i in numbers: if pick == 0: print("Tails!") else: print("Heads!")and this is the error I'm getting:

It seems to me that the first automatic input is supposed to generate only one flip, and then for the second time, it generates 5, but I don't know how to do that. Perhaps it's actually supposed to always generate 5 and I'm doing something wrong in my code.
Thanks in advance!
