Skip to content

Instantly share code, notes, and snippets.

<iframe src="https://scratch.mit.edu/projects/PROJECTID/embed" width="800" height="600"></iframe>
@richardbwest
richardbwest / demo1.py
Created June 23, 2019 19:09
Python ANSI Colors Tutorial example
import os
os.system("cls") #use this for windows. change to os.system("clear") for linux
COLORS = {\
"black":"\u001b[30;1m",
"red": "\u001b[31;1m",
"green":"\u001b[32m",
"yellow":"\u001b[33;1m",
"blue":"\u001b[34;1m",
@richardbwest
richardbwest / higherorlowercardgame.py
Created February 8, 2019 23:16
Higher or Lower Card Game tutorial
import time, os, random
ranks = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]
suits = ["Clubs","Hearts","Diamonds","Spades"]
deck = []
value = 1
for rank in ranks:
for suit in suits:
deck.append([rank + " of " + suit, value])
@richardbwest
richardbwest / minecraftteleporter.py
Created August 29, 2018 12:45
A working teleporter in the minecraft world using Python
#Full tutorial video available at - http://learnlearn.uk/raspberrypi/2018/08/29/make-teleporter-minecraft-using-python/
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
mc = minecraft.Minecraft.create()
mc.postToChat("Welcome to my teleporter")
@richardbwest
richardbwest / waitinggame.py
Created August 28, 2018 11:33
Python Waiting Game Tutorial Code.
import random, time,os
while True: #infinite loop
os.system('cls') # linux - clear
print("Welcome to the waiting game!")
print("\n\n")
print("Instructions\n")
print("You will be told to wait a number of seconds.")
print("Wait that number of seconds and then press ENTER")
print("Are you ready? Press ENTER to start...")
@richardbwest
richardbwest / flappybird.py
Created August 27, 2018 15:56
Simple Flappybird style game in Minecraft coded using Python
import mcpi.minecraft as minecraft
import mcpi.block as block
import random, time
mc = minecraft.Minecraft.create()
def drawPillar(x):
@richardbwest
richardbwest / rockscissorspaper.py
Created August 23, 2018 11:18
A simple implementation of a rock, paper scissors game.
import random,time
userScore = 0
compScore = 0
choices = ["r","p","s"]
rnd = 1
while True: #Infinite Loop
@richardbwest
richardbwest / shoppinglist.py
Created August 20, 2018 17:21
Python Shopping List Program
import os,sys,time
sl = []
try:
f = open("shopping2.txt","r")
for line in f:
sl.append(line.strip())
f.close()
except:
pass
@richardbwest
richardbwest / minecraftcastle.py
Created August 18, 2018 11:23
Minecraf castle code using Python.
import datetime,time,math
import mcpi.minecraft as minecraft
import mcpi.block as block
mc = minecraft.Minecraft.create()
mc.setBlocks(-100,0,-100,100,100,100,block.AIR)
def drawTower(tx,ty,tz):
@richardbwest
richardbwest / writetocsv.py
Last active May 22, 2018 10:52
Simple example of how to write to a CSV File using Python
import csv
f = open('scores.csv','a') # 'a' stands for APPEND / ADD TO
# use 'w' if you want to replace the whole file's contents...
writer = csv.writer(f)
fname = input("First name: ")
lname = input("Last name: ")