Note: Click on "Kernel" > "Restart Kernel and Run All" in JupyterLab after finishing the exercises to ensure that your solution runs top to bottom without any errors. If you cannot run this file on your machine, you may want to open it in the cloud .
The exercises below assume that you have read the first part of Chapter 1.
The ...
's in the code cells indicate where you need to fill in code snippets. The number of ...
's within a code cell give you a rough idea of how many lines of code are needed to solve the task. You should not need to create any additional code cells for your final solution. However, you may want to use temporary code cells to try out some ideas.
Q1: Concatenate greeting
and audience
below with the +
operator and print out the resulting message "Hello World"
with only one call of the built-in print() function!
Hint: You may have to "add" a space character in between greeting
and audience
.
greeting = "Hello"
audience = "World"
print(...)
Q2: How is your answer to Q1 an example of the concept of operator overloading?
< your answer >
Q3: Read the documentation on the built-in print() function! How can you print the above message without concatenating
greeting
and audience
first in one call of print() ?
Hint: The *objects
in the documentation implies that we can put several expressions (i.e., variables) separated by commas within the same call of the print() function.
print(...)
first = "Anthony"
second = "Berta"
third = "Christian"
print(...)
Q5: Lastly, what does the end="\n"
mean in the documentation? Adjust and use it within the for
-loop to print the numbers 1
through 10
on one line with only one call of the print() function!
for number in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
print(...)