CHALLENGE FOR ALL SOLOLEARNERS(PYTHON) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

CHALLENGE FOR ALL SOLOLEARNERS(PYTHON)

I challenged myself to make a program that flips a coin a hundred times and shows if its head or tails for each time it flips but I have no idea how to go about it. Already started but my code is a mess.

1st Sep 2017, 6:26 AM
Poet🎭
Poet🎭 - avatar
5 Answers
+ 11
Idk, Python isn't my main. By flip, do you mean flip it to the other side? Something like: coin = True for i in range(0, 100): coin = not coin print ('heads' if coin else 'tails') or is it a coin toss which results in a 'random' face?
1st Sep 2017, 7:07 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Oh thanks.
1st Sep 2017, 10:17 AM
Poet🎭
Poet🎭 - avatar
+ 4
A little Python code here, I hope it helps... https://code.sololearn.com/cDL25CD4aVa6/#py
2nd Sep 2017, 2:24 PM
noobcøder
noobcøder - avatar
+ 1
from random import randrange for i in range(100): print('head' if randrange(2) else 'tail') you can also create the list of results that way : l = [randrange(2) for i in range(100)]
1st Sep 2017, 7:34 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
1st Sep 2017, 11:10 PM
ysraelcon
ysraelcon - avatar