Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

!

"#$%&'()*+$'(%,)+-
!"#$%&'"#()$&(*+,-$.(/&0#-(/$%&#"(12#,("34,4$.56()&$7(8$(9,0&'-(*&"##:

!"#$%&'"#()$&(*+"(#"'$,-("-.*.$,(/&"(+"&"0(12-(3$4"(*$(5,$6(6+/*(7$%(*+.,5(/8$%*(97*+$,
:&/#+(:$%&#";(<3"/#"('$,#.-"&(*/5.,=(/(8&.")(#%&4"70(1)(7$%2-(3.5"(*$(5,$6(6+",(/--.*.$,/3
&"#$%&'"#(/&"(/4/.3/83">(7$%('/,(#.=,(%<()$&("?/.3(,$*.@'/*.$,#(+"&"0

!"#$%&"'()*)+,-.%/0)1
!"#$%&'()*+
!",$%-./*(01'%2345'()
!"6$%78*)).(9
!":$%78*)).(9%,
!";$%<0/'()
!"!$%&*880+=
!">$%&'*?8'
!"@$%&'1)
!"A$%-./*(01'%&8.B')
!"#C$%-./*(01'%2345'()
!"##$%D010')

E.BF%1*%)*8310*+)G

!"#$%&'()*+
H)'%.%I0B10*+.(9%1*%)1*('%0+J*(4.10*+%.5*31%.%?'()*+%9*3%F+*KG%L1*('%1M'0(%N()1%+.4'O%8.)1%+.4'O
.='O%.+I%1M'%B019%0+%KM0BM%1M'9%80/'G%P*3%)M*38I%M./'%F'9)%)3BM%.)% first_name O% last_name O% age O%.+I
city G%&(0+1%'.BM%?0'B'%*J%0+J*(4.10*+%)1*('I%0+%9*3(%I0B10*+.(9G

person = {
'first_name': 'eric',
'last_name': 'matthes',
'age': 43,
'city': 'sitka',
}

print(person['first_name'])
print(person['last_name'])
print(person['age'])
print(person['city'])

Q31?31$

eric
matthes
43
sitka

1*?

!",$%-./*(01'%2345'()
H)'%.%I0B10*+.(9%1*%)1*('%?'*?8'R)%J./*(01'%+345'()G%SM0+F%*J%N/'%+.4')O%.+I%3)'%1M'4%.)%F'9)%0+
9*3(%I0B10*+.(9G%SM0+F%*J%.%J./*(01'%+345'(%J*(%'.BM%?'()*+O%.+I%)1*('%'.BM%.)%.%/.83'%0+%9*3(
I0B10*+.(9G%&(0+1%'.BM%?'()*+R)%+.4'%.+I%1M'0(%J./*(01'%+345'(G%-*(%'/'+%4*('%J3+O%?*88%.%J'K
J(0'+I)%.+I%='1%)*4'%.B13.8%I.1.%J*(%9*3(%?(*=(.4G

favorite_numbers = {
'mandy': 42,
'micah': 23,
'gus': 7,
'hank': 1000000,
'maggie': 0,
}

num = favorite_numbers['mandy']
print("Mandy's favorite number is " + str(num) + ".")

num = favorite_numbers['micah']
print("Micah's favorite number is " + str(num) + ".")

num = favorite_numbers['gus']
print("Gus's favorite number is " + str(num) + ".")

num = favorite_numbers['hank']
print("Hank's favorite number is " + str(num) + ".")

num = favorite_numbers['maggie']
print("Maggie's favorite number is " + str(num) + ".")

Q31?31$

Mandy's favorite number is 42.


Micah's favorite number is 23.
Gus's favorite number is 7.
Hank's favorite number is 1000000.
Maggie's favorite number is 0.

1*?

!"6$%78*)).(9
T%&91M*+%I0B10*+.(9%B.+%5'%3)'I%1*%4*I'8%.+%.B13.8%I0B10*+.(9G%U*K'/'(O%1*%./*0I%B*+J3)0*+O%8'1R)
B.88%01%.%=8*)).(9G

SM0+F%*J%N/'%?(*=(.440+=%K*(I)%9*3R/'%8'.(+'I%.5*31%0+%1M'%?('/0*3)%BM.?1'()G%H)'%1M')'
K*(I)%.)%1M'%F'9)%0+%9*3(%=8*)).(9O%.+I%)1*('%1M'0(%4'.+0+=)%.)%/.83')G
&(0+1%'.BM%K*(I%.+I%01)%4'.+0+=%.)%+'.189%J*(4.11'I%*31?31G%P*3%40=M1%?(0+1%1M'%K*(I
J*88*K'I%59%.%B*8*+%.+I%1M'+%01)%4'.+0+=O%*(%?(0+1%1M'%K*(I%*+%*+'%80+'%.+I%1M'+%?(0+1%01)
4'.+0+=%0+I'+1'I%*+%.%)'B*+I%80+'G%H)'%1M'%+'K80+'%BM.(.B1'(%V '\n' W%1*%0+)'(1%.%58.+F%80+'
5'1K''+%'.BM%K*(I"4'.+0+=%?.0(%0+%9*3(%*31?31G

glossary = {
'string': 'A series of characters.',
'comment': 'A note in a program that the Python interpreter ignores.',
'list': 'A collection of items in a particular order.',
'loop': 'Work through a collection of items, one at a time.',
'dictionary': "A collection of key-value pairs.",
}

word = 'string'
print("\n" + word.title() + ": " + glossary[word])

word = 'comment'
print("\n" + word.title() + ": " + glossary[word])

word = 'list'
print("\n" + word.title() + ": " + glossary[word])

word = 'loop'
print("\n" + word.title() + ": " + glossary[word])

word = 'dictionary'
print("\n" + word.title() + ": " + glossary[word])

Q31?31$

String: A series of characters.

Comment: A note in a program that the Python interpreter ignores.

List: A collection of items in a particular order.

Loop: Work through a collection of items, one at a time.

Dictionary: A collection of key-value pairs.

1*?

!":$%78*)).(9%,
2*K%1M.1%9*3%F+*K%M*K%1*%8**?%1M(*3=M%.%I0B10*+.(9O%B8'.+%3?%1M'%B*I'%J(*4%XY'(B0)'%!"6%V?.='
#C,W%59%('?8.B0+=%9*3(%)'(0')%*J% print %)1.1'4'+1)%K01M%.%8**?%1M.1%(3+)%1M(*3=M%1M'%I0B10*+.(9R)
F'9)%.+I%/.83')G%ZM'+%9*3R('%)3('%1M.1%9*3(%8**?%K*(F)O%.II%N/'%4*('%&91M*+%1'(4)%1*%9*3(
=8*)).(9G%ZM'+%9*3%(3+%9*3(%?(*=(.4%.=.0+O%1M')'%+'K%K*(I)%.+I%4'.+0+=)%)M*38I%.31*4.10B.889
5'%0+B83I'I%0+%1M'%*31?31G

glossary = {
'string': 'A series of characters.',
'comment': 'A note in a program that the Python interpreter ignores.',
'list': 'A collection of items in a particular order.',
'loop': 'Work through a collection of items, one at a time.',
'dictionary': "A collection of key-value pairs.",
'key': 'The first item in a key-value pair in a dictionary.',
'value': 'An item associated with a key in a dictionary.',
'conditional test': 'A comparison between two values.',
'float': 'A numerical value with a decimal component.',
'boolean expression': 'An expression that evaluates to True or False.',
}

for word, definition in glossary.items():


print("\n" + word.title() + ": " + definition)

Q31?31$

Dictionary: A collection of key-value pairs.

String: A series of characters.

Boolean Expression: An expression that evaluates to True or False.

Comment: A note in a program that the Python interpreter ignores.

Value: An item associated with a key in a dictionary.

Loop: Work through a collection of items, one at a time.

List: A collection of items in a particular order.

Conditional Test: A comparison between two values.

Key: The first item in a key-value pair in a dictionary.

Float: A numerical value with a decimal component.

1*?

!";$%<0/'()
[.F'%.%I0B10*+.(9%B*+1.0+0+=%1M(''%4.\*(%(0/'()%.+I%1M'%B*3+1(9%'.BM%(0/'(%(3+)%1M(*3=MG%Q+'%F'9"
/.83'%?.0(%40=M1%5'% 'nile': 'egypt' G

H)'%.%8**?%1*%?(0+1%.%)'+1'+B'%.5*31%'.BM%(0/'(O%)3BM%.)%!"#$%&'#$()*+$,"(-)."$/.01,2
H)'%.%8**?%1*%?(0+1%1M'%+.4'%*J%'.BM%(0/'(%0+B83I'I%0+%1M'%I0B10*+.(9G
H)'%.%8**?%1*%?(0+1%1M'%+.4'%*J%'.BM%B*3+1(9%0+B83I'I%0+%1M'%I0B10*+.(9G

rivers = {
'nile': 'egypt',
'mississippi': 'united states',
'fraser': 'canada',
'kuskokwim': 'alaska',
'yangtze': 'china',
}

for river, country in rivers.items():


print("The " + river.title() + " flows through " + country.title() + ".")

print("\nThe following rivers are included in this data set:")


for river in rivers.keys():
print("- " + river.title())

print("\nThe following countries are included in this data set:")


for country in rivers.values():
print("- " + country.title())

Q31?31]$

The Mississippi flows through United States.


The Yangtze flows through China.
The Fraser flows through Canada.
The Nile flows through Egypt.
The Kuskokwim flows through Alaska.

The following rivers are included in this data set:


- Mississippi
- Yangtze
- Fraser
- Nile
- Kuskokwim

The following countries are included in this data set:


- United States
- China
- Canada
- Egypt
- Alaska

]L*4'104')%K'%80F'%1*%1M0+F%*J%T8.)F.%.)%*3(%*K+%)'?.(.1'%B*3+1(9G

1*?

!"!$%&*880+=
H)'%1M'%B*I'%0+%345-(&,#6'4*.)4.#+210%V?.='%#C:WG

[.F'%.%80)1%*J%?'*?8'%KM*%)M*38I%1.F'%1M'%J./*(01'%8.+=3.=')%?*88G%^+B83I'%)*4'%+.4')%1M.1
.('%.8('.I9%0+%1M'%I0B10*+.(9%.+I%)*4'%1M.1%.('%+*1G
_**?%1M(*3=M%1M'%80)1%*J%?'*?8'%KM*%)M*38I%1.F'%1M'%?*88G%^J%1M'9%M./'%.8('.I9%1.F'+%1M'%?*88O
?(0+1%.%4')).='%1M.+F0+=%1M'4%J*(%(')?*+I0+=G%^J%1M'9%M./'%+*1%9'1%1.F'+%1M'%?*88O%?(0+1%.
4')).='%0+/010+=%1M'4%1*%1.F'%1M'%?*88G

favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}

for name, language in favorite_languages.items():


print(name.title() + "'s favorite language is " +
language.title() + ".")

print("\n")

coders = ['phil', 'josh', 'david', 'becca', 'sarah', 'matt', 'danielle']


for coder in coders:
if coder in favorite_languages.keys():
print("Thank you for taking the poll, " + coder.title() + "!")
else:
print(coder.title() + ", what's your favorite programming language?")

Q31?31$

Jen's favorite language is Python.


Sarah's favorite language is C.
Phil's favorite language is Python.
Edward's favorite language is Ruby.

Thank you for taking the poll, Phil!


Josh, what's your favorite programming language?
David, what's your favorite programming language?
Becca, what's your favorite programming language?
Thank you for taking the poll, Sarah!
Matt, what's your favorite programming language?
Danielle, what's your favorite programming language?

1*?

!">$%&'*?8'
L1.(1%K01M%1M'%?(*=(.4%9*3%K(*1'%J*(%XY'(B0)'%!"#%V?.='%#C,WG%[.F'%1K*%+'K%I0B10*+.(0')
('?(')'+10+=%I0`'('+1%?'*?8'O%.+I%)1*('%.88%1M(''%I0B10*+.(0')%0+%.%80)1%B.88'I% people G%_**?%1M(*3=M
9*3(%80)1%*J%?'*?8'G%T)%9*3%8**?%1M(*3=M%1M'%80)1O%?(0+1%'/'(91M0+=%9*3%F+*K%.5*31%'.BM%?'()*+G

# Make an empty list to store people in.


people = []

# Define some people, and add them to the list.


person = {
'first_name': 'eric',
'last_name': 'matthes',
'age': 43,
'city': 'sitka',
}
people.append(person)

person = {
'first_name': 'ever',
'last_name': 'matthes',
'age': 5,
'city': 'sitka',
}
people.append(person)

person = {
'first_name': 'willie',
'last_name': 'matthes',
'age': 8,
'city': 'sitka',
}
people.append(person)

# Display all of the information in the dictionary.


for person in people:
name = person['first_name'].title() + " " + person['last_name'].title()
age = str(person['age'])
city = person['city'].title()

print(name + ", of " + city + ", is " + age + " years old.")

Q31?31$

Eric Matthes, of Sitka, is 43 years old.


Ever Matthes, of Sitka, is 5 years old.
Willie Matthes, of Sitka, is 8 years old.

1*?

!"@$%&'1)
[.F'%)'/'(.8%I0B10*+.(0')O%KM'('%1M'%+.4'%*J%'.BM%I0B10*+.(9%0)%1M'%+.4'%*J%.%?'1G%^+%'.BM
I0B10*+.(9O%0+B83I'%1M'%F0+I%*J%.+04.8%.+I%1M'%*K+'(R)%+.4'G%L1*('%1M')'%I0B10*+.(0')%0+%.%80)1%B.88'I
pets G%2'Y1O%8**?%1M(*3=M%9*3(%80)1%.+I%.)%9*3%I*%?(0+1%'/'(91M0+=%9*3%F+*K%.5*31%'.BM%?'1G

%-,#7$8"#*$9$:#;&:#:$,-$1-+,$+-'),&-*+$4*:$<(-,#$;-=1'#,#$1(-.(4=+$,-$+-'5#$#4;"$#>#(;&+#?$9
(#4'&@#:$,"&+$1(-A'#=$<4+$*-,$4+$<#''$1"(4+#:$4+$&,$+"-)':$"45#$A##*2$9,$:-#+*B,$(#4''0$=4C#$+#*+#
,-$*4=#$#4;"$:&;,&-*4(0$3-($,"#$1#,$&,$:#+;(&A#+D$,"4,$&*3-(=4,&-*$+"-)':$(#4''0$A#$&*;'):#:$&*$,"#
:&;,&-*4(0?$(4,"#($,"4*$A#&*.$)+#:$4+$,"#$*4=#$-3$,"#$:&;,&-*4(02$!"&+$+-'),&-*$(#E#;,+$,"4,
411(-4;"2

# Make an empty list to store the pets in.


pets = []

# Make individual pets, and store each one in the list.


pet = {
'animal type': 'python',
'name': 'john',
'owner': 'guido',
'weight': 43,
'eats': 'bugs',
}
pets.append(pet)

pet = {
'animal type': 'chicken',
'name': 'clarence',
'owner': 'tiffany',
'weight': 2,
'eats': 'seeds',
}
pets.append(pet)

pet = {
'animal type': 'dog',
'name': 'peso',
'owner': 'eric',
'weight': 37,
'eats': 'shoes',
}
pets.append(pet)

# Display information about each pet.


for pet in pets:
print("\nHere's what I know about " + pet['name'].title() + ":")
for key, value in pet.items():
print("\t" + key + ": " + str(value))

Q31?31$

Here's what I know about John:


weight: 43
animal type: python
name: john
owner: guido
eats: bugs

Here's what I know about Clarence:


weight: 2
animal type: chicken
name: clarence
owner: tiffany
eats: seeds

Here's what I know about Peso:


weight: 37
animal type: dog
name: peso
owner: eric
eats: shoes

1*?

!"A$%-./*(01'%&8.B')
[.F'%.%I0B10*+.(9%B.88'I% favorite_places G%SM0+F%*J%1M(''%+.4')%1*%3)'%.)%F'9)%0+%1M'%I0B10*+.(9O
.+I%)1*('%*+'%1*%1M(''%J./*(01'%?8.B')%J*(%'.BM%?'()*+G%S*%4.F'%1M0)%'Y'(0B)'%.%501%4*('%0+1'(')10+=O
.)F%)*4'%J(0'+I)%1*%+.4'%.%J'K%*J%1M'0(%J./*(01'%?8.B')G%_**?%1M(*3=M%1M'%I0B10*+.(9O%.+I%?(0+1
'.BM%?'()*+R)%+.4'%.+I%1M'0(%J./*(01'%?8.B')G

favorite_places = {
'eric': ['bear mountain', 'death valley', 'tierra del fuego'],
'erin': ['hawaii', 'iceland'],
'ever': ['mt. verstovia', 'the playground', 'south carolina']
}

for name, places in favorite_places.items():


print("\n" + name.title() + " likes the following places:")
for place in places:
print("- " + place.title())

Q31?31$

Ever likes the following places:


- Mt. Verstovia
- The Playground
- South Carolina

Erin likes the following places:


- Hawaii
- Iceland

Eric likes the following places:


- Bear Mountain
- Death Valley
- Tierra Del Fuego

1*?

!"#C$%-./*(01'%2345'()
[*I0J9%9*3(%?(*=(.4%J(*4%XY'(B0)'%!",%V?.='%#C,W%)*%'.BM%?'()*+%B.+%M./'%4*('%1M.+%*+'%J./*(01'
+345'(G%SM'+%?(0+1%'.BM%?'()*+R)%+.4'%.8*+=%K01M%1M'0(%J./*(01'%+345'()G

favorite_numbers = {
'mandy': [42, 17],
'micah': [42, 39, 56],
'gus': [7, 12],
}

for name, numbers in favorite_numbers.items():


print("\n" + name.title() + " likes the following numbers:")
for number in numbers:
print(" " + str(number))

Q31?31$

Micah likes the following numbers:


42
39
56

Mandy likes the following numbers:


42
17

Gus likes the following numbers:


7
12

1*?

!"##$%D010')
[.F'%.%I0B10*+.(9%B.88'I% cities G%H)'%1M'%+.4')%*J%1M(''%B010')%.)%F'9)%0+%9*3(%I0B10*+.(9G%D('.1'%.
I0B10*+.(9%*J%0+J*(4.10*+%.5*31%'.BM%B019%.+I%0+B83I'%1M'%B*3+1(9%1M.1%1M'%B019%0)%0+O%01)%.??(*Y04.1'
?*?38.10*+O%.+I%*+'%J.B1%.5*31%1M.1%B019G%SM'%F'9)%J*(%'.BM%B019R)%I0B10*+.(9%)M*38I%5'%)*4'1M0+=
80F'% country O% population O%.+I% fact G%&(0+1%1M'%+.4'%*J%'.BM%B019%.+I%.88%*J%1M'%0+J*(4.10*+%9*3%M./'
)1*('I%.5*31%01G

cities = {
'santiago': {
'country': 'chile',
'population': 6158080,
'nearby mountains': 'andes',
},
'talkeetna': {
'country': 'alaska',
'population': 876,
'nearby mountains': 'alaska range',
},
'kathmandu': {
'country': 'nepal',
'population': 1003285,
'nearby mountains': 'himilaya',
}
}

for city, city_info in cities.items():


country = city_info['country'].title()
population = city_info['population']
mountains = city_info['nearby mountains'].title()

print("\n" + city.title() + " is in " + country + ".")


print(" It has a population of about " + str(population) + ".")
print(" The " + mountains + " mountains are nearby.")

Q31?31$

Santiago is in Chile.
It has a population of about 6158080.
The Andes mountains are nearby.

Kathmandu is in Nepal.
It has a population of about 1003285.
The Himilaya mountains are nearby.

Talkeetna is in Alaska.
It has a population of about 876.
The Alaska Range mountains are nearby.

1*?

!"#$%&'()*+$'(%,)+-'.+'/*.&#*.&-0'1"'-$/*##$-+2
!"#$%&'()%*'$%()+),'-).%/0%1#-23/%4'()$%3$#+(%-")%5'06'+%-")6)%/0%7'$8+%98+(:

You might also like