To do this exercise, download this notebook and open it on your own computer. There are several tasks described below. Your job is to change the code in the cells so that the output from running the cell matches the expected output indicated above the cell.
Add parentheses to the Python statement below so that it prints out the value 7.0.
10 + 4 / 2
Change the operator in the statement below so that it displays
True instead of
14 > 15
Change the variable assignment below so that the cell evaluates to the number 32.
my_number = 17 my_number
Three variables are assigned below, all with different types.
Replace the word
None inside the parentheses of type() in the print
statement below so that it prints
x = 14 y = 17.4 z = "mother said there'd be days like these" type(None)
Modify the statement below so that it displays the string "We aren't friends now." (i.e., change "are" to "aren't".) Use a single quoted string---don't change it to double quotes.
We aren't friends now.
print('We are friends now.')
In the cell below, on a line directly following the two variable assignments, write an expression that evaluates to the sum of the lengths of the two string variables defined in the cell (
second_line). Use the
first_line = "It was the best of times." second_line = "It was the worst of times." # your code here
Inside the parentheses of the
window in the string defined in the variable called
romeo. Use the
romeo = "But, soft! what light through yonder window breaks?" # your code here!
Modify the expression inside the parentheses of the
and the horse you rode in on
benediction = " and the horse you rode in on \n" print(benediction)
Using the previously defined
benediction variable, write an
expression in the parentheses of the
AND THE HORSE YOU RODE IN ON
print(benediction) # your code here!
Modify the value assigned to variable
offset below so that the expression at the bottom of the cell evaluates to
Modify the values assigned to variables
end below so that the expression at the bottom of the cell evaluates to the string
start = 0 end = 10 romeo = "But, soft! what light through yonder window breaks?" romeo[start:end]
Modify the statement below so that it displays the number 100. Do this using the int() function (hint: you need to use it twice).
print("19" + "81")