Practice problems: Week 1ΒΆ

The purpose of these problems is to allow you to test you understanding of the material we have covered so far. It is intended to take an hour or so, assuming you have done the reading.

To get started run git pull upstream master, which will pick up a directory named pp1.

The problems are broken up into two parts: a set of “be-a-computer” warm-up exercises and a set of programming problems. You should do the warm-up exercises by hand. You can check your answer by running the Python program warmup.py in pp1. We will be using a system named Kattis for the programming problem. Kattis is a website that allows students to submit solutions to programming problems, and have them evaluated automatically by running a series of test cases on the submitted solutions. You can find information about how to use Kattis here. You can find the skeleton code needed for the programming problems in pp1.

Warm-up exercise #1: What is the value of w after evaluating the following code?

x = 7
y = 5.0
z = 10.0
w = x % 2 + y / z + z + y / (z + z)

Warm-up exercise #2: What is the value of c after evaluating the following code?

c = True
d = False
c = c and d
c = not c or d

Warm-up exercise #3: What is the output generated by the following program?

d = 0
for p in range(0, 5):
    if p % 4 == 0:
        d = d + (p-1) * 25;
    else:
        d = d + 100;
print("$" + str(d//100) + "." + str(d % 100))

Programming problem #1: Outside range.

Programming problem #2: Divisible by.