Download the notebook here
Exercise 1 (solution)#
In this notebook you do your first steps in Python
Task 1: Hello World#
define a function called hello that takes no arguments and prints Hello World! if it is called.
[ ]:
def hello():
print("Hello World!")
hello()
Task 2: Strings#
[ ]:
a = "I like programming"
Split the variable a into three words and assign these words to the variables a1, a2 and a3.
[ ]:
a1, a2, a3 = a.split()
a2
Task 3: Dictionaries#
define a dictionaries that maps names to a level of Python knowledge. As names you can take your name and the names of a few friends. The Python knowledge should be rated on a scale from 0 to 10.
[ ]:
names_to_skills = {
"Janos": 8,
"Tobi": 10,
"Mariam": 9,
}
Now loop over the keys and values of this dictionary and print a nicely formatted message. For example for me, the message that should be printed is:
'Janos has a python level of 8.'
[ ]:
for name, level in names_to_skills.items():
print(f"{name} has a python level of {level}")
Task 4: Lists#
Write a loop that takes that adds the next eight Fibonacci numbers to the list [1, 1]
[ ]:
numbers = [1, 1]
for _i in range(8):
numbers.append(numbers[-2] + numbers[-1])
numbers
[ ]: