Expressions Worksheet
Problem 1
The program below should result in a printed output of hello, world! – be careful, the correct output should have a trailing space!
print("hello,")
print("world! ")hello, world! Problem 2
The program below should print:
12
21Note that it includes several lines at the end that can’t be changed: modify the beginning of the program so that it results in the desired output.
x = (4 * 2) + 1
y = 4 * (2 + 2print(y)
print(x + y)12
21Problem 3
The program below should print:
1
6Note that it includes several lines at the end that can’t be changed: modify the beginning of the program so that it results in the desired output.
x = 2
y = x - 2
# hint: add a print statementy = 2 + x
print(x + y)1
6Problem 4
The program below should print:
9
4x = 6
y = 0print(x * (2 + y))
y = x // 2
print(y)9
4Problem 5
x = "a space at the end"
y = "makes a difference"print(x + y + z)a space at the end
makes a difference Problem 6
The print statements in this program use the end = keyword argument to change what happens after the printed output:
- Normally, printing goes onto the next line
- Calling print with the end =changes this
- Experiment and figure it out!
x = "spacing"
y = "matters!"print(x * 5, end = " ")
print(y)spacing      matters!Problem 7
Remember how the + operator behaves differently depending on what it operates on! This should print 5.0.
x = 3print(x + 2)5.0Problem 8
Remember how the + operator behaves differently depending on what it operates on!
The desired printed output is:
is three the same as 3?three = 3print("is three the same as " + three + "?")is three the same as 3?