The objective of this assignment is to give you practice with the basic programming concepts, basic
Python syntax, and tools. The assignment consists of 4 exercises and covers the following:
While the lab instructor walks around checking lecture exercises (pre-lab) on individual basis, start
working with the assigned partner on exercise sets 2 and 3. Once you are done with a set, check with
the one of the other pairs sitting next to you regarding their progress – help each other. Then, as a
pair, present your solutions to the lab instructor. Each student is to have his version of the
programs/answers and be capable of presenting them for the pair. The presenter will be chosen at
random by the lab instructor. All the exercises other than the last set need to be shown to the lab
instructor before leaving the lab for full credit. The last exercise set may be finished at home and
shown in the beginning of the subsequent lab session. Use IDLE unless indicated otherwise.
1. Lecture Exercises (20%)
Show the following programs you were to create and save during the lecture:
2. Python as Calculator / Operator Precedence (20%)
Execute appropriate statements at the command prompt and write down the answers:
a. Compute the number of seconds in 8 weeks _______________
b. Assume a group of 5 children who are 5, 7, 11, 12, 14 and calculate their average age using
floating point division _______________
c. Assume a group of 5 children who are 5, 7, 11, 12, 14 and calculate their average age using
integer division _______________ . Is the resulting number rounded up or down?
d. Write an expression that uses the modulo operator and yields 1 as the result. Use any two
numbers that will leave a remainder of 1 to do this. _______________
e. Find the volume of a sphere with radius 11 _______________ and radius 6.5
_______________ . The formula for the volume is:
f. Evaluate the following four expressions and explain why they produce different results
7 / 3 * 1.2 + 3 / 2 _______________
7 // 3 * 1.2 + 3 / 2 _______________
7 // 3 * 1.2 + 3 // 2 _______________
7 / 3 * 1.2 + 3 // 2 _______________
g. Evaluate the expression 30 – 3 ** 2 + 8 / 3 ** 2 * 10 _______________. Then rewrite
the expression using at least 4 sets of parentheses so that you get the same output.
3. Basic Variables, Expressions, Print (30%)
– 2 –
a. Given the following sequence of commands:
State the values of each variable after each line is executed.
Line number a b c
1 4 – –
b. Create a complete Python program called bday.py that declares five variables and assigns
appropriate values to them.
your birthday month (1-12)
your birthday day (1-31)
the birthday month of your partner (1-12)
the birthday day of your partner (1-31)
your partner’s name
Ask your neighbor for their name and for the proper numbers to store in the variables for
his/her birthday. Then produce output in this format using your four variables:
My birthday is 9/19, and Suzy’s is 6/14.
4. Debugging and Command-Line (30%)
a. Download the program called tricky.py. It contains several errors. Find and fix them.
Once you fix one mistake, you will want to re-run the program before fixing another one. You
will want to run the program in IDLE and see what kinds of error messages are shown for
each kind of mistake – you will see such messages over and over again, so this is the good time
to learn their meaning. The program should produce the following output:
“Take some more tea,” the March Hare said to Alice, very earnestly.
“I’ve had nothing yet,” Alice replied in an offended tone, “so I can’t take
“You mean you can’t take less,” said the Hatter: “it’s very easy to take more
b. Download the program called tricky2.py. It contains several errors. Find and fix them.
The program should produce the following output:
x is 0
x is now 15
x and y are 15 and 16
—– THE END —–
a = 4
b = 9
c = a ** b
b = b ** b
c = c + a ** b
a = b % 7