Skip to content

Instantly share code, notes, and snippets.

@richardbwest
richardbwest / goodbadstrings.py
Created July 20, 2016 11:13
Examples of valid and invalid strings in Python
"hello world" -# Okay! :-)
'hello world' - #Okay! :-)
"hello world' - #No Good :-(
@richardbwest
richardbwest / spiderpig.py
Created July 20, 2016 12:12
Example of string concatenation
str1 = "spider"
str2 = "pig"
str3 = str1 + str2
print(str3)
@richardbwest
richardbwest / mathsbracketspython.py
Created July 20, 2016 13:56
Example of maths with brackets in Python
print((4 * 5) + 2)
print(4 * (5 + 2))
#Try typing these lines above in to python
#Do the come up with the same answer or a different answer?
@richardbwest
richardbwest / andgate.py
Created July 21, 2016 08:57
Simple and gate example in Python
print(True and True)
print(True and False)
print(False and False)
@richardbwest
richardbwest / aladdinscave.py
Created July 21, 2016 13:11
Simple if statement.
username = input("Please enter your username:")
password = input("Please enter your password:")
if username == "aladin" and password == "abracadabra":
print("You can enter the cave of many shiny treasures")
@richardbwest
richardbwest / favcolororgateexample.py
Created July 21, 2016 13:35
Python OR gate example using favourite colour
fav = input("What's your favourite color?")
if fav == "green" or fav == "brown":
print("That's one of my favourite colors too!")
movie = input("What's your favourite movie?")
if not movie == "Monty Python's Life of Brian":
print("You father was a hamster and your mother smelled of elderberries!")
#Simple darts game
#Each player gets 6 attempts to score as close to 180 as possible.
#If your total is over 180 you are bust and you lose
import os
total = 0
for i in range(6):
os.system('clear')
print("Current score - " +str(total) + "\n\n")
for i in range(100):
choice = input("Do you want to stop now?")
if choice == "yes":
break
print("Goodbye then!")
import time,os
stickmen = [
"\
|------\n\
| O\n\
| ---|---\n\
| / \\ \n\
| / \\ \n\
|_____",