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
# Python 2.7 | |
# let's have the computer tell us "hello world!" | |
# Remember, a computer program is a set of instructions we tell the computer what to do. | |
print("Hello World!") | |
# When we run the program, Python returns the string inside the parentheses | |
# a string is just any series of letters, numbers, or symbols. Think of it as a line of text. |
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
# Python 2.7 | |
# A simple program to have the computer take input from the user... Or so it seems! | |
message = ("Tell me something, and I will repeat it back to you: ") | |
print(message) | |
# Now, the message is printed, but the user cannot type anyhting in! | |
# What function do we need to add and where? |
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
# By: Wray | |
# 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
# The following is a gist of gist by Wray. | |
# We know all about loops and conditionals, so let's create a simple search by first name. | |
# Here's where we define our function | |
def find_contact_by_first_name(first_name): | |
for contact in contacts: # and here is our for loop found within the function's block of code | |
if contact[0] == first_name: | |
return contact | |
contact = find_contact_by_first_name("John") |
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
# Python 2.7 | |
# Example from Python Crash Course | |
# Here's another example of nesting a list inside of a dictionary | |
# looking at our previous example of a dicitonary of similar objects | |
favorite_languages = { | |
'jen': ['python', 'ruby'], | |
'sarah': ['c'], | |
'edward': ['ruby', 'go'], | |
'phil': ['python', 'haskell'], |
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
# Python 2.7 | |
# example from Python Crash Course by Eric Matthes | |
# you can store different kinds of information about one object in a dictionary, | |
# you can also use a dictionary to store one kind of information about many objects. | |
# Let's say we wanted to poll a number of people and ask them what their favorite programming language is. | |
# A dictionary can be useful for storing the results of a simple poll: |
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
# Python 2.7 | |
# example from Python Crash Course by Eric Matthes | |
# store info about a pizza being ordered | |
# list in a dictionary | |
pizza = { | |
'crust':'thick', | |
'toppings': ['mushrooms', 'pepperoni', 'extra cheese'], | |
} | |
# summarize the order: |
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
# Python 2.7 | |
# Objectives: modules, game surface, Frames/sec (FPS), "skeleton" of a game, game loop, color, | |
# setting object size, random, lists | |
# Rather than typing from scratch (only ~50min of lecture available), students will | |
# each have these lines of code for a basic snake game using pygame. | |
# Lines will either be omitted or commented out | |
# students will follow along via the instructor/whiteboard; either typing in a few lines of code where its needed | |
# and/or students will uncomment lines of code that carry out specific feature related to the objectives |
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
from dictionary import * # importing another program so we can use its code in this new program | |
# START WITH AN EMPTY LIST | |
classmates = [] | |
# USING THE APPEND FUNCTION TO ADD DICTIONARIES TO THE EMPTY LIST | |
classmates.append(john) | |
classmates.append(jane) | |
classmates.append(sue, james, bart) # adding multiple dictionaries at one time |
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
# Python 2.7 | |
# By Joe | |
# Below is a basic review of dictionaries in Python | |
# starting with an empty dictionary, then adding information to it | |
# Example: | |
# MAKE AN EMPTY DICTIONARY | |
john = {} | |
# ADDING KEY-VALUE PAIRS TO THE DICTIONARY |