Skip to content

Commit

Permalink
Commit all the things!
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdnetworks committed Jun 9, 2018
1 parent 8493d52 commit 60f0bd6
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ex38.py
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!

62 changes: 62 additions & 0 deletions ex39.py
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}")


19 changes: 19 additions & 0 deletions ex40.py
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()
2 changes: 2 additions & 0 deletions ex40a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mystuff = {'groot': "I AM GROOT!"}
print(mystuff['groot'])
3 changes: 3 additions & 0 deletions ex40b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import mystuff
mystuff.groot()
print(mystuff.stark)
4 changes: 4 additions & 0 deletions ex40c.py
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
13 changes: 13 additions & 0 deletions mystuff.py
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)


4 changes: 4 additions & 0 deletions mystuffold.py
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."

0 comments on commit 60f0bd6

Please sign in to comment.