# Beyond Monty Karel

Beyond Monty Karel is intended to provide material for a first course in computing that begins with Monty Karel. It has some interesting example programs and demonstrates some advanced Python coding techniques.

Threre is an introduction to some important data structures such as lists and trees.

It also has a term-long project to build something like the infrastructure for the Monty Karel system itself.

Errata: A few errors have been found in early printings. These are being corrected as they are found. If you have an early printing this listing will point out the corrections.

Preface

9 The State of the Computation

9.1 Implicit State
9.1.1 Assertions
9.2 The Program Counter
9.3 Explicit State (Introduction)
9.4 Primitive Data
9.5 Making Use of Arithmetic on int Values
9.6 A Program Using Numeric Data and Built by Composition
9.6.1 A Calculator Model with a Display
9.6.2 Numeric Keys
9.6.3 Accumulation
9.6.4 Operators
9.6.5 The Equals Key
9.7 Simple Functions
9.8 Other Primitive and Built-In Types in Python
9.9 Modules, Scope of Variables, and More on Naming
9.10 Introduction to Tuples, and Lists
9.11 Introduction to Sorting
9.12 A Few Python Tricks and Shortcuts
9.13 Important Ideas From This Chapter
9.14 Problem Set
9.15 Solution to Towers of Hanoi

10 Input, Output, and Exception Handling

10.1 File Output
10.2 Exceptions
10.3 File Input For Text
10.4 File At A Time Input
10.5 Character At a Time Input
10.7 A Simple I/O Illustration
10.8 Introduction to Graphical User Interface Programming: Dialogs
10.9 Important Ideas From This Chapter
10.10 Problem Set

Primo Intermezzo – The French Military Game

1 The Game
2 Move Rules
3 The Display
4 The Police
5 The Fox
6 Playing the Game
7 The Memory Manager
8 A Dialog for User Inputs
9 Important Ideas From This Intermezzo
10 Problem Set

11 Collections

11.1 Collections Framework Overview
Specifics of Some Built-in Collection Types
11.2 Collections Exploration – Part 1, Variations
11.3 List Structures
Dense Lists
11.4 Tree Structures
11.5 Collections Exploration – Part 2, The MemoryManager
11.6 Collections Exploration – Part 3, The Police class
11.7 Important Ideas From This Chapter
11.8 Problem Set

12 Testing and Documentation

12.1 Documentation Overview
12.2 Python dir and help – Automated Documentation
dir
help
12.3 Testing Overview
12.4 unittest – Automated Testing
12.4.1 Overview
12.4.2 Testing Example – The Calculator Again
12.5 Important Ideas From This Chapter
12.6 Problem Set

Secondo Intermezzo – A Toy Computer

1 Introduction to Machine Language
2 The Memory and Its Contents
3 The Execution Stack
4 The Toy Computer
5 Running the Program
6 More Convenient Programming – Assembly Language
7 Important Ideas From This Intermezzo
8 Problem Set

13 Queues, Priority Queues, and Huffman Coding

13.1 Queues and Priority Queues
13.2 Huffman Coding – The Problem
13.3 Huffman Coding – The Data Structures
13.4 Huffman Coding – The Process
13.5 Decoding the Result
13.6 Encoding the Translation Tree – More Recursion
13.7 Important Ideas From This Chapter
13.8 Problem Set

14 Project and Case Study – MiniKarel

14.1 Overview
14.2 State, Building MiniRobot
14.3 Two Dimensional Structures and I/O, Extending the World
14.4 Collections, Neighbors
14.5 Documentation and Testing
14.6 Dialogs, Refactoring, and Polymorphism

Bibliography and Resources

Appendix

Python Operators
Precedence of operators
Python special forms
Simplified Data Structures
1 A Dense List Implementation