Professional Documents
Culture Documents
Python Crash Course by Ehmatthes 6
Python Crash Course by Ehmatthes 6
"#$%&'()*+$'(%,)+-
!"#$%&'"#()$&(*+,-$.(/&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$
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$
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.',
}
Q31?31$
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',
}
Q31?31]$
]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',
}
print("\n")
Q31?31$
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
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)
print(name + ", of " + city + ", is " + age + " years old.")
Q31?31$
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
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)
Q31?31$
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']
}
Q31?31$
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],
}
Q31?31$
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',
}
}
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+(: