Unit 0 - Practice Problems
These problems are for practice. They are optional, but you are encouraged to complete them and discuss them with members of the course staff during lab and office hours.
0 - Mathematical Operators - Example
What is printed by the following program?
1 - Mathematical Operators
What is printed by the following program?
2 - Mathematical Operators
What is printed by the following program?
3 - Mathematical Operators
What is printed by the following program?
4 - Mathematical Operators
What is printed by the following program?
5 - Mathematical Operators
What is printed by the following program?
6 - Mathematical Operators
What is printed by the following program?
7 - Strings
This program intends to print: The sky in the West was red and black.
s = 'The sky in the West was'
color1 = 'red'
color2 = 'black'
print(s + color1 + 'and' + color2 + '.')
Does it produce this output? If not, why not?
8 - Strings
This program intends to print: 1 3 5 7 9 11
Does it produce this output? If not, why not?
9 - Strings
This program intends to print:
2 squared is 4
5 squared is 25
8 squared is 64
There is an error on Line 2. Rewrite Line 2 so that the correct output will print.
10 - Variable Types
This program intends to print:
123
Does it produce this output? If not, why not?
11 - Variable Types
This program intends to print:
1
22
333
It does not produce this output. Rewrite Line 2 so that this output is produced.
12 - Functions
Which of these programs prints the following output:
A screaming comes across the sky.
A.
B.
C.
D.
13 - Whitespace and Formatting
What is the difference, if any, between these two programs’ output? Both programs can be highlighted and copied for inspection.
First program.
Second program.
14 - Whitespace and Formatting
Several of these programs produce the same output. Identify them. All programs can be highlighted and copied for inspection.
A.
B.
C.
D.
E.
15 - Whitespace and Formatting
What is the difference, if any, between these programs’ output?