Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 3a38095

Browse files
Merge pull request #402 from pranavdasan/pranav/add-coin-flip
Created coinflip.py
2 parents 9e6af9a + b3e8ed4 commit 3a38095

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

projects/Coin Flip/coinflip.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import random
2+
import os
3+
4+
5+
6+
while True:
7+
global answer_y
8+
9+
#Clears the shell/terminal (where all the text is)
10+
os.system('clear')
11+
12+
answer = input("Pick a side for the coin toss: ")
13+
14+
list1 = ["heads", "tails"]
15+
16+
# Picks randonly from the list
17+
random_s = random.choice(list1)
18+
19+
print("You got... "+ random_s)
20+
21+
if answer.lower() == random_s:
22+
# Tells the user if they won
23+
print("Nice you won the coin toss!!")
24+
25+
# Asks the user if they want to play again
26+
answer_y = input("Wanna play agian? ")
27+
if answer_y.lower() == "no":
28+
break
29+
30+
if answer.lower() != random_s:
31+
# Tells the user if they lost
32+
print("OOF.")
33+
34+
# Asks the user if they want to play again
35+
answer_y = input("Wanna play agian? ")
36+
if answer_y.lower() == "no":
37+
break
38+
39+
40+

0 commit comments

Comments
 (0)