Skip to content

Instantly share code, notes, and snippets.

@IanMcT
IanMcT / aliens.py
Created November 26, 2016 11:41
This is the example ga,e that comes woth pygame. Image and sound files needed to run it.
#!/usr/bin/env python
import random, os.path
#import basic pygame modules
import pygame
from pygame.locals import *
#see if we can load more than standard BMP
if not pygame.image.get_extended():
@IanMcT
IanMcT / linear_search.py
Created November 14, 2016 03:45
Demo of linear search
#I McTavish
#Nov 13, 2016
#Linear search - measure how long a linear search takes
import datetime #used to track time
def linear_search(value, list):
for i in range(len(list)):
if list[i] == value:
return i
return "item not found"
@IanMcT
IanMcT / favicon.ico
Created November 13, 2016 11:05
Template for hangman.
 hF ��00 �%V@@ (B�:(  @�������������������|||�ppp�fff�www駧�����U������������������������uVVV�AAA�����������������ddd�GGG��������#��������������Ǔ666���������������������������������]]]��������)���������cFFF�����������������������������������������ccc�������� ��� ���댌����������������������������������������������zzz����w���]<<<�|||���������������������������������zzz�zzz���������������ܟXXX�����bbb�###�����vvv�___�����FFF�����ttt�������������������̹hhh���������+++���������888�����~~~���������������������������йfff��������������������������%%%�ccc������������������������JJJ����������555�sss�������������@@@�����\\\�===������������]zzz�ddd�\\\���������bbb�����������������ooo����������������� ����jjj���������������������������������������������rrr����w������clll���������������������������������������������������� ���������jjj���������������������������������~~~��������)���������������u����MMM�����
@IanMcT
IanMcT / hangman01.gif
Created November 13, 2016 11:03
Template for hangman game.
GIF89a,��3f���++3+f+�+�+�UU3UfU�U�U���3�f��������3�f��������3�fՙ������3�f������3333f3�3�3�3+3+33+f3+�3+�3+�3U3U33Uf3U�3U�3U�3�3�33�f3��3��3��3�3�33�f3��3��3��3�3�33�f3ՙ3��3��3�3�33�f3��3��3��ff3fff�f�f�f+f+3f+ff+�f+�f+�fUfU3fUffU�fU�fU�f�f�3f�ff��f��f��f�f�3f�ff��f��f��f�f�3f�ffՙf��f��f�f�3f�ff��f��f����3�f���̙��+�+3�+f�+��+̙+��U�U3�Uf�U��U̙U�����3��f�����̙������3��f�����̙������3��f�ՙ��̙������3��f�����̙����3�f�������+�+3�+f�+��+��+��U�U3�Uf�U��U��U�̀̀3̀f̀�̀�̀�̪̪3̪f̪�̪�̪�����3��f�ՙ����������3��f�����������3�f�������+�+3�+f�+��+��+��U�U3�Uf�U��U��U�����3��f�������������3��f�������������3��f�ՙ����������3��f���������!��,,��� H����*\Ȱ�Ç#J�H��ŋ3j�ȱ�Ǐ C�I��ɓ(S�\ɲ�˗0cʜI��͛8s��ɳ�ϟ@�
J��ѣH�*]ʴ�ӧP�J�J��իX�j�ʵ�ׯ`ÊK��ٳhӪ]˶�۷p�ʝK��ݻx���˷�߿� L���È+^̸��ǐ#K�L���˘3k��̹��ϠC�M�.�ӨS�^ͺ��װc˞���Eڸs��ͻ�튽� .�7E�ȓ+gm|���Ћ7���l����Վ�!��߻+ ����濦?Op}W�����:�|����翺z����T�V
#Sudoku solver
#by http://stackoverflow.com/questions/1697334/algorithm-for-solving-sudoku
#username hari
#Solves Sudoku puzzles.
def findNextCellToFill(grid, i, j):
for x in range(i,9):
for y in range(j,9):
if grid[x][y] == 0:
return x,y
for x in range(0,9):
@IanMcT
IanMcT / fractals.py
Created November 8, 2016 03:25
Koch fractals
import turtle
def koch(t, order, size):
"""
Make turtle t draw a Koch fractal of 'order' and 'size'.
Leave the turtle facing the same direction.
"""
if order == 0: # The base case is just a straight line
t.forward(size)
else:
@IanMcT
IanMcT / hangman_template.py
Created November 7, 2016 11:04
Modified a comment.
#I McTavish
#Nov 3, 2016
#Create a template for hangman game.
import tkinter
from tkinter import font
class MyGUI:
"""The class that handles the window"""
def __init__(self):
#main window
@IanMcT
IanMcT / hangman_template.py
Created November 7, 2016 11:02
Template for hangman game.
#I McTavish
#Nov 3, 2016
#Create a template for hangman game.
import tkinter
from tkinter import font
class MyGUI:
"""The class that handles the window"""
def __init__(self):
#main window
@IanMcT
IanMcT / temp_converter.py
Created November 7, 2016 01:50
Demonstrates how to use methods in a program.
#I McTavish
#Nov 2, 2016
#Demonstrate methods with temp convertor
def convert_c_to_f(c):
"""Method to convert Celsius to Fahrenheit
Pre: Celsius temp
Post: Fahrenheit temp"""
f = 9/5*c+32
return format(f,".2f")
@IanMcT
IanMcT / address_book.py
Created November 2, 2016 13:55
Modify based on comments
#Name
#Date
#Add global variable - a list of addresses
#open button should open a set text file
#and load addresses
#close should save using the list
#When open first item displayed
#next moves to next item
import tkinter