Skip to content

Instantly share code, notes, and snippets.

@nsmaciej
Last active December 15, 2015 08:19
Show Gist options
  • Save nsmaciej/5229605 to your computer and use it in GitHub Desktop.
Save nsmaciej/5229605 to your computer and use it in GitHub Desktop.
My first ever python program.
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