Skip to content

Instantly share code, notes, and snippets.

@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",
<iframe src="https://scratch.mit.edu/projects/PROJECTID/embed" width="800" height="600"></iframe>
@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 / 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 / typewriter with input.py
Created December 3, 2020 13:37
How to do typewriter text with inputs in python
import sys,time
message = "please enter your name: "
def typewriter(message):
for char in message:
sys.stdout.write(char)
sys.stdout.flush()
if char != "\n":
import random,time,os
l = [i for i in range(10)]
random.shuffle(l)
def redraw(arrow = "↑",shift=0,moved_right=False):
os.system('cls')
print()
print("Outer Index:",index, "\tCurrentValue: ",currentValue, "\tInner Index:",currentPosition)
print()
@richardbwest
richardbwest / bubblesort.py
Created November 4, 2020 23:26
Bubble Sort Algorithm Tutorial
import time,random
l = []
for i in range(20):
l.append(random.randint(1,1000))
def bubble_sort(l):
l = l[:]
while True:
swapped = False
import mcpi.minecraft as minecraft
import mcpi.block as block
import time,math
mc = minecraft.Minecraft.create()
mc.postToChat("Rainbow World")
pos = mc.player.getTilePos()
@richardbwest
richardbwest / maze_solver.py
Last active June 25, 2020 15:15
Recursive Maze Solving Algorithm in Python Demonstrating Tree Recursion
import csv,os,time,sys,random
def get_maze(file):
f = open(file,'r')
reader = csv.reader(f)
maze = []
for line in reader:
maze.append(line)
return maze
@richardbwest
richardbwest / filefoldertraversalrecursion.py
Created June 2, 2020 02:04
Recursive File System Traversal
# Adapted from - http://openbookproject.net/thinkcs/python/english3e/recursion.html
def get_dirlist(path):
"""
Return a sorted list of all entries in path.
This returns just the names, not the full path to the names.
"""
try:
dirlist = os.listdir(path)
dirlist.sort()