Skip to content

Instantly share code, notes, and snippets.

from graphics import *
#
# We decided that we would like to have a button class that
# draws a rectangle with a text label and also provides a
# method that can be used to test if a point is within its bounds.
# That is, a method to see if the button has been "clicked".
class Button(Rectangle):
def __init__(self,p1,p2,text):
# Choose your own adventure game
# MARS
# I am importing the Button class we created -- I created mine in a file
# called button.py (in the same directory)
from button import *
# Create a window
win = GraphWin("Mars Adventure",500,600)
# Put your commands here
COMMAND1 = ""
# Your handling code goes in this function
def handle_command(command):
"""
Determine if the command is valid. If so, take action and return
a response, if necessary.
"""
response = ""
# Pre-req's : loops, conditionals, functions, lists, tuples, and dictionaries
#
# Python 2.7
#
# Objectives : Advanced dicionaries, Overloaded term: index, Multiple indexes
# Data is at the heart of most computation. Remember, the earliest computers helped people
# "store" their counts - tally sticks. Today's computer systems are excellent data storage
# systems. So, it makes sense to learn some about how computer programs store and retrieve data.
@wray
wray / data2.py
Last active March 25, 2017 18:25
# Pre-req's : loops, conditionals, functions, lists, tuples, and dictionaries
#
# Python 2.7
#
# Objectives : Advanced dictionaries, handling key collisions
# Remember in the previous lesson, we defined a contact record using the following tuple
contact = ('first_name','last_name','mobile_phone','home_phone','zip_code')
@wray
wray / data3.py
Last active March 25, 2017 22:33
# Pre-req's : loops, conditionals, functions, lists, tuples, and dictionaries
#
# Python 2.7
#
# Objectives: Advanced dictionaries, dictionaries as list indices
# Foundational Objectives: Databases
#
# Remember in the previous lessons, we defined a contact record using the following tuple
@wray
wray / binary_adder.py
Created October 20, 2017 20:23
Binary Adder
#
# To use these functions, you can run python and then import like -
# from binary_adder import *
#
# These methods carry out binary addition via 'digital logic'
# This is really what happens at the logic circuit level.
# So, this is a pretty abstract use of programming to illustrate
# what happens on silicon using code many, many, levels above that!
#
@wray
wray / brute-pin.py
Created January 28, 2018 20:45
Simple example for brute force pin guessing
import time
import itertools
def brute_force_digits(pin):
""" Uses itertools to create a cartesian product of the possible pins """
for guess in list(itertools.product(list(range(10)),repeat=len(str(pin)))):
if pin == int(len(str(pin))*'%d' % (guess)):
return guess
@wray
wray / brute-pin-wren.py
Created January 28, 2018 20:47
Uses PyWren to submit pin guess to lambda
import pywren
import time
import itertools
def brute_force_digits(pin):
""" Uses itertools to create a cartesian product of the possible pins """
for guess in list(itertools.product(list(range(10)),repeat=len(str(pin)))):
if pin == int(len(str(pin))*'%d' % (guess)):
return guess
@wray
wray / brute-pin-divide.py
Last active January 28, 2018 21:13
Break up the problem to reduce memory needed
import time
import itertools
def brute_force_digits(pin):
""" Uses itertools to create a cartesian product of the possible pins """
for guess in list(itertools.product(list(range(10)),repeat=len(str(pin)))):
if pin == int(len(str(pin))*'%d' % (guess)):
return guess
def brute_force_split(pin,n):