-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8493d52
commit 60f0bd6
Showing
8 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ten_things = "Apples Oranges Crows Telephone Light Sugar" | ||
|
||
print("Wait. There are not 10 things in that list. Let's fix that.") | ||
|
||
stuff = ten_things.split(' ') | ||
more_stuff = ["Day", "Night", "Song", "Frisbee", | ||
"Corn", "Banana", "Girl", "Boy"] | ||
|
||
while len(stuff) != 10: | ||
next_one = more_stuff.pop() | ||
print("Adding: ", next_one) | ||
stuff.append(next_one) | ||
print(f"There are {len(stuff)} items now.") | ||
|
||
print("There we go: ", stuff) | ||
|
||
print("Let's do some thigns with stuff.") | ||
|
||
print(stuff[1]) | ||
print(stuff[-1]) # whoa! fancy | ||
print(stuff.pop()) | ||
print(' '.join(stuff)) # What? Cool! | ||
print('#'.join(stuff[3:5])) # super stellar! | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# create a mappung of state to abbreiation | ||
|
||
states = { | ||
'Oregon': 'OR', | ||
'Florida': 'FL', | ||
'California': 'CA', | ||
'New York': 'NY', | ||
'Michigan': 'MI' | ||
} | ||
|
||
# create a basic set of states and some cities in them | ||
|
||
cities = { | ||
'CA': 'San Francisco', | ||
'MI': 'Detroit', | ||
'FL': 'Jacksonville' | ||
} | ||
|
||
# add some more missions | ||
|
||
cities['NY'] = 'New York' | ||
cities['OR'] = 'Corvallis' | ||
|
||
# print out some cities | ||
|
||
print('-' * 10) | ||
print("NY State has: ", cities['NY']) | ||
print("OR State has: ", cities['OR']) | ||
|
||
# print some states | ||
|
||
print('-' * 10) | ||
print("Michigan has: ", cities[states['Michigan']]) | ||
print("Florida has: ", cities[states['Florida']]) | ||
|
||
# print every state abbreviation | ||
print('-' * 10) | ||
for state, abbrev in list(states.items()): | ||
print(f"{state} is abbreviated {abbrev}") | ||
|
||
# print every city in a state | ||
print('-' * 10) | ||
for abbrev, city in list(cities.items()): | ||
print(f"{abbrev} has the city {city}") | ||
|
||
# now do both at the same time | ||
print('-' * 10) | ||
for state, abbrev in list(states.items()): | ||
print(f"{state} state is abbreviated {abbrev}") | ||
print(f"and has city {cities[abbrev]}") | ||
|
||
print('-' * 10) | ||
# Safely get a abbreviation by state that might not be there | ||
state = states.get('Texas') | ||
if not state: | ||
print("Sorry, no Texas.") | ||
|
||
# get a city without a defaulte value | ||
city = cities.get('TX', 'Does not Exist') | ||
print(f"The city for the state of 'TX' is: {city}") | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Song(object): | ||
|
||
def __init__(self, lyrics): | ||
self.lyrics = lyrics | ||
|
||
def sing_me_a_song(self): | ||
for line in self.lyrics: | ||
print(line) | ||
|
||
happy_bday = Song(["Happy birtday to you", | ||
"I don't want to get sued", | ||
"So I'll stop right there"]) | ||
|
||
bulls_on_parade = Song(["They all really around the family", | ||
"With pockets full of shells"]) | ||
|
||
happy_bday.sing_me_a_song() | ||
|
||
bulls_on_parade.sing_me_a_song() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mystuff = {'groot': "I AM GROOT!"} | ||
print(mystuff['groot']) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import mystuff | ||
mystuff.groot() | ||
print(mystuff.stark) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import mystuff | ||
#mystuff['groot'] # get groot from a dict | ||
mystuff.groot() # get groot from a module | ||
print(mystuff.stark) # same thing. just a variable |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class MyStuff(object): | ||
|
||
def __init__(self): | ||
self.stark = "I am classy Iron Man." | ||
|
||
def groot(self): | ||
print("I am classy groot!") | ||
|
||
thing = MyStuff() | ||
thing.groot() | ||
print(thing.stark) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def groot(): | ||
print("I AM GROOT!") | ||
|
||
stark = "I am Iron Man." |