Introduction to the Code Examples

This page gives access to code examples related to subjects covered in COP 3223H at UCF, as taught by Gary T. Leavens.

There are sections on:


Programming with Python

See for documentation and tutorial information about Python.

Python numeric functions

Python output (print) and Numerical Calculations

Python printing and procedures

The examples in the section mostly print song lyrics for repeatitive songs. Note that these have also been made into programs that print the song lyrics when run.

Python interaction

The following examples show how to combine input and output in a Python program.

Python Booleans, Boolean Expressions, and Predicate Functions

The following are examples of predicates (Boolean-valued functions) in Python.

Python String Formatting

The following demonstrate the format method of strings in Python.

Higher-order Functions and Procedures in Python

Following the Grammar with Python (Recursion and Recursive Data)

Most of the examples in this section are described in detail in the technical report, "Following the Grammar with Python" (CS-TR-17-01, February 2017).
Grammars and Classes
Only Alternatives, No Recursion
Only Recursion, No Alternatives
Multiple Nonterminals
Combination of Different Grammar Types
Lisp Lists
Binary Trees
Sales Data

Tail Recursion

This is an extra credit topic. The following are examples of tail-recursive functions.

Loops (while and for loops)

Most examples in this section include systematic developments with loop invariants and assertions. In assertions we use implies (see above) and allIntsIn (see below).

While Loops and break
For Loops and continue

The functions allIntsIn and someIntsIn act as quantifiers for assertions over ranges.

Programming with C

There is a draft standard for C available online at The C Library Reference Guide is also useful as a reference.

Input and Output with Variables

Testing for C programs

You can download our testing files for C programs from This zip file includes the following two modules.

We will be using libtap, by Jacob Gelbman, for testing of C programs. It can be obtained from (by clicking on the green "clone or download" button), or you can simply use the provided files: tap.h and tap.c.

For testing whole programs that read and write stdin and stdout, we will make use of a custom C module, called testing_io. The module's header file is testing_io.h, and its implementation is in testing_io.c. To use it we require that you write a whole program as a function that takes no arguments and returns an int, and that the testing file be compiled with both testing_io.c and tap.c, which must reside in the same directory as the testing file.

The module quantifiers.c with header in quantifiers.h contains some helping functions (allIntsIn and someIntsIn) for testing. These act as universal and existential quantifiers over int ranges. See test_quantifiers.c.

Booleans and Conditionals in C

Arrays and Loops in C

Pointers in C

Structs (and pointers to structs) in C

Last modified $Date: 2017/04/24 19:31:46 $.