AutomateTheBoringStuff.Ch10 package

Submodules

AutomateTheBoringStuff.Ch10.P1_boxPrint module

P1_boxPrint.py

This program prints out a box based on input sizes.

AutomateTheBoringStuff.Ch10.P1_boxPrint.boxPrint(symbol: str, width: int, height: int) → None[source]

Box print

Prints a box of given width and height using the given symbol.

Parameters:
  • symbol – String to use to make sides of box.
  • width – Integer width of box.
  • height – Integer height of box.
Returns:

None. Prints box to specified dimensions.

Raises:

Exception – If symbol != 1 or if either width or height <= 2.

AutomateTheBoringStuff.Ch10.P1_boxPrint.main()[source]

AutomateTheBoringStuff.Ch10.P2_errorExample module

Error Example

This program raises an exception and automatically displays the traceback.

AutomateTheBoringStuff.Ch10.P2_errorExample.bacon() → None[source]

Bacon

Raises base exception.

Returns:None.
Raises:Exception – Always
AutomateTheBoringStuff.Ch10.P2_errorExample.main()[source]
AutomateTheBoringStuff.Ch10.P2_errorExample.spam() → None[source]

Spam

Calls bacon().

Returns:None.

AutomateTheBoringStuff.Ch10.P3_writeLogfile module

Write logfile

This program raises an exception but outputs traceback to a logfile.

Note

Default logfile is errorInfo.txt

AutomateTheBoringStuff.Ch10.P3_writeLogfile.main()[source]

AutomateTheBoringStuff.Ch10.P4_podBayDoor module

Pod Bay Door

This program raises an AssertionError.

Note

Correction submitted for line 13

AutomateTheBoringStuff.Ch10.P4_podBayDoor.main()[source]

AutomateTheBoringStuff.Ch10.P5_trafficLight module

Traffic light

This program emulates traffic lights at intersections with assertions.

AutomateTheBoringStuff.Ch10.P5_trafficLight.market_2nd

Stoplight at the corner of Market and 2nd streets with North-South face and East-West face as keys.

Type:dict
AutomateTheBoringStuff.Ch10.P5_trafficLight.mission_16th

Stoplight at the corner of Mission and 16th streets with North-South face and East-West face as keys.

Type:dict
AutomateTheBoringStuff.Ch10.P5_trafficLight.main()[source]
AutomateTheBoringStuff.Ch10.P5_trafficLight.switchLights(stoplight: dict) → None[source]

Switch lights

Takes stoplight dictionary and changes values: from ‘green’ to ‘yellow’, ‘yellow’ to ‘red’, and ‘red’ to ‘green’.

Parameters:stoplight – Dictonary representing stoplight with face directions as keys and status as values.
Returns:None. Changes dictionary values.
Raises:AssertionError – If none of the dictionary values are ‘red’.

AutomateTheBoringStuff.Ch10.P6_factorialLog module

Factorial log

This program calculates factorial and logs debug messages.

AutomateTheBoringStuff.Ch10.P6_factorialLog.factorial(n: int) → int[source]

Factorial

Calculates factorial of given number.

Parameters:n – Integer number to calculate factorial.
Returns:Factorial of given number.
AutomateTheBoringStuff.Ch10.P6_factorialLog.main()[source]

AutomateTheBoringStuff.Ch10.P7_buggyAddingProgram module

Buggy adding program

This program adds three user inputted numbers and displays the sum.

Note

May not work as expected.

AutomateTheBoringStuff.Ch10.P7_buggyAddingProgram.main()[source]

AutomateTheBoringStuff.Ch10.P8_coinFlip module

Coin flip

This program simulates flipping a coin 1000 times and prints the number of times it landed on heads.

AutomateTheBoringStuff.Ch10.P8_coinFlip.main()[source]

Module contents