This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book: | |
def __init__(self,pages): | |
self.pages = pages | |
self.current_page = 0 | |
self.bookmark = 0 | |
def read(self): | |
return self.current_page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Let's go back to some games and start | |
# playing with a multi-sided dice. | |
# | |
# Think of the dice and how we interact with the dice. | |
# We roll it and then we read the number. | |
# | |
# The self keyword is similar to a | |
# regular variable, except it is a variable for every object | |
# created. A way to access the object in the class definition code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Choose your own adventure game | |
# MARS | |
def bad_alien(): | |
print("The object fires a laser at you!") | |
def friendly_alien(): | |
print("A little alien comes from the object with some spare O2 for you.") | |
print("You land on mars and your oxygen generator has failed, so you only have a few hours on the planet. However, you see something in the distance! What do you do?") | |
choice = raw_input("A) Leave Now, B) Go to object, or C) Scan Object ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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! | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# An example program to calculate weight on moon after a certain number | |
# of years. We are assuming someone who currently weighs more than 150 will only | |
# gain .5 pounds a year, while lighter individuals will gain 2 pounds a year. | |
# This is the concept we just learned. Defining a function in python. | |
# We use a function to calculate moon weight, mWeight after a certain number | |
# of years, years. | |
def moon_weight(current_weight,years): |