Last active
December 15, 2015 08:19
-
-
Save nsmaciej/5229605 to your computer and use it in GitHub Desktop.
My first ever python program.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
coin = 't' | |
texts = {"t": "tail", "h": "head"} | |
def start(): | |
while True: | |
toss = random.randint(0,1) | |
guessed = raw_input("Choose [h]ead or [t]ail or [q]uit: ") | |
if guessed == "q": | |
sys.exit(0) | |
elif guessed not in ["t", "h"]: | |
print("Incorrect input try agin") | |
else: | |
if toss == 0: | |
coin = "t" | |
else: | |
coin = "h" | |
if guessed == coin: | |
#print(bytes("You won, it was " + texts[coin], "utf-8").decode("unicode_escape")) | |
print("\033[1;32m" + "You won, it was " + texts[coin] + "\033[1;m") | |
else: | |
print("\033[1;31m" + "You loose, it was " + texts[coin] + "\033[1;m") | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment