Python Crash Course by Ehmatthes 11
Python Crash Course by Ehmatthes 11
"#$%&'()*+$'(%,)+-
!"#$%&'"#()$&(*+,-$.(/&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)11
!!"!#$%&'()$%*+,'-(
!!".#$/*0+12'&*,
!!"3#$4501*(66
7289$'*$:*1+'&*,:;
!!"!#$%&'()$%*+,'-(
<-&'6$2$=+,8'&*,$'>2'$28860':$'?*$02-256'6-:#$2$8&'($,256$2,@$2$8*+,'-($,256;$A>6$=+,8'&*,
:>*+1@$-6'+-,$2$:&,B16$:'-&,B$*=$'>6$=*-5$!"#$%&!'()#*$)$:+8>$2:$ Santiago, Chile ;$C'*-6$'>6$=+,8'&*,
&,$2$5*@+16$82116@$+"#$,-()+#"')./0$;
%-62'6$2$D16$82116@$#1.#,+"#"1./0$$'>2'$'6:':$'>6$=+,8'&*,$(*+$E+:'$?-*'6$F-6565G6-$'>2'$(*+$,66@$'*
&50*-'$ unittest $2,@$'>6$=+,8'&*,$(*+$?2,'$'*$'6:'H;$<-&'6$2$56'>*@$82116@$ test_city_country() $'*
I6-&=($'>2'$8211&,B$(*+-$=+,8'&*,$?&'>$I21+6:$:+8>$2:$ santiago $2,@$ chile $-6:+1':$&,$'>6$8*--68'$:'-&,B;
J+,$#1.#,+"#"1./0$)$2,@$5296$:+-6$ test_city_country() $02::6:;
+"#$,-()+#"')./0$2
!"#$%&34".&".)&-()+#"')&51&5*'#1&")&671*+".1&89:/
#1.#,+"#"1./0$2
import unittest
class CitiesTestCase(unittest.TestCase):
"""Tests for 'city_functions.py'."""
def test_city_country(self):
"""Does a simple city and country pair work?"""
santiago_chile = city_country('santiago', 'chile')
self.assertEqual(santiago_chile, 'Santiago, Chile')
unittest.main()
K+'0+'#
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
'*0
!!".#$/*0+12'&*,
L*@&=($(*+-$=+,8'&*,$:*$&'$-6M+&-6:$2$'>&-@$02-256'6-)$ population ;$N'$:>*+1@$,*?$-6'+-,$2$:&,B16
:'-&,B$*=$'>6$=*-5$ City, Country - population xxx )$:+8>$2:$ Santiago, Chile - population 5000000 ;
J+,$#1.#,+"#"1./0$$2B2&,;$L296$:+-6$ test_city_country() $=2&1:$'>&:$'&56;
K+'0+'$=-*5$-+,,&,B$#1.#,+"#"1./0$2
E
======================================================================
ERROR: test_city_country (__main__.CitiesTestCase)
Does a simple city and country pair work?
----------------------------------------------------------------------
Traceback (most recent call last):
File "pcc\solutions\test_cities.py", line 10, in test_city_country
santiago_chile = city_country('santiago', 'chile')
TypeError: city_country() missing 1 required positional argument: 'population'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
K+'0+'$*=$-+,,&,B$#1.#,+"#"1./0$2
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
L*@&D6@$#1.#,+"#"1./0$2
import unittest
class CitiesTestCase(unittest.TestCase):
"""Tests for 'city_functions.py'."""
def test_city_country(self):
"""Does a simple city and country pair work?"""
santiago_chile = city_country('santiago', 'chile')
self.assertEqual(santiago_chile, 'Santiago, Chile')
def test_city_country_population(self):
"""Can I include a population argument?"""
santiago_chile = city_country('santiago', 'chile', population=5000000)
self.assertEqual(santiago_chile, 'Santiago, Chile - population 5000000')
unittest.main()
K+'0+'#
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
'*0
!!"3#$4501*(66
<-&'6$2$812::$82116@$ Employee ;$A>6$ __init__() $56'>*@$:>*+1@$'296$&,$2$D-:'$,256)$2$12:'$,256)$2,@
2,$2,,+21$:212-()$2,@$:'*-6$628>$*=$'>6:6$2:$2''-&G+'6:;$<-&'6$2$56'>*@$82116@$ give_raise() $'>2'
2@@:$OPQQQ$'*$'>6$2,,+21$:212-($G($@6=2+1'$G+'$21:*$28860':$2$@&R6-6,'$-2&:6$25*+,';
1;0<'$11/0$2
class Employee():
"""A class to represent an employee."""
#1.#,1;0<'$11/0$2
import unittest
class TestEmployee(unittest.TestCase):
"""Tests for the module employee."""
def setUp(self):
"""Make an employee to use in tests."""
self.eric = Employee('eric', 'matthes', 65000)
def test_give_default_raise(self):
"""Test that a default raise works correctly."""
self.eric.give_raise()
self.assertEqual(self.eric.salary, 70000)
def test_give_custom_raise(self):
"""Test that a custom raise works correctly."""
self.eric.give_raise(10000)
self.assertEqual(self.eric.salary, 75000)
unittest.main()
K+'0+'#
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
'*0
!"#$%&'()*+$'(%,)+-'.+'/*.&#*.&-0'1"'-$/*##$-+2
!"#$%&'()%*'$%()+),'-).%/0%1#-23/%4'()$%3$#+(%-")%5'06'+%-")6)%/0%7'$8+%98+(: