Write your own print
statement in the code cell below. Follow the syntax of the example above, and change the text in the quotation marks.
# Write your own awesome print statement here!
print('Hi, I\'m Tom')
Hi, I'm Tom
Try using Shift + Enter to run the following cell three times. What is the output? Run the cell one more time. Is the output the same?
ANSWER: a
keeps increasing. This is because each time we run the cell, the value in memory is updated and 1 is added.
The following two blocks of code include variable names that cause an error. For each block of code, consider the following questions:
# use consistent style (e.g. snake case)
avg_age = 30.332
another_variable = 28.801
print(avg_age - another_variable)
1.5310000000000024
# Variable names cannot include symbols like .
country_1 = 'Zimbabwe'
# Variable names are case-sensitive
continent = 'Africa'
print(country_1, 'is a country in', continent)
Zimbabwe is a country in Africa
What does the following error seem to tell you? Google the error and see if you can fix it!
# SyntaxError: unmatched ')'
# We need to remove the second closing parenthesis
print('something went wrong')
something went wrong
Let's say we have two variables and we want to swap the values for each of them.
Does the following method accomplish the goal?
💡 Tip: What is the value of first and last at the end of the cell?
start = 1997
end = 1952
start = end
end = start
Using a third temporary variable (you could call it temp
), swap the first and last variables, so that start = 1952
and end = 1997
.
start = 1997
end = 1952
# YOUR CODE HERE
temp = start
start = end
end = temp
print(start,end)
1952 1997