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:
![Click Photo To Enlarge 11](https://i.ibb.co/GcwL7DM/11.png)
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:![Click Photo To Enlarge 22](https://i.ibb.co/1rRvdgZ/22.png)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is my code:
![Click Photo To Enlarge 33](https://i.ibb.co/W5j3Dpq/33.png)
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:
![Click Photo To Enlarge 11](https://i.ibb.co/GcwL7DM/11.png)
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:
![Click Photo To Enlarge 22](https://i.ibb.co/1rRvdgZ/22.png)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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:
![Click Photo To Enlarge 33](https://i.ibb.co/W5j3Dpq/33.png)
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!
![Cool Cool](https://python-forum.io/images/smilies/cool.png)