from assertions import *
from test_cells import *Assignment 1.1
You can also perform more advanced operations using the operators //, % and **. Let’s try it out! Using these three operators, return the quotient of a divided by b (rounded to the next smallest whole number), the remainder of a divided by b and finally a raised to the power of b.
Expected input
15
4Expected return values
3, 3, 50625# Code for assignment 1.1
def assignment_1_1(a, b):
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 1.1
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_1_1(assignment_1_1)# Assertion for assignment 1.1
check_assertion(assignment_1_1)Assignment 1.2
Precedence describes the order in which operations are performed. Parentheses have the highest precedence, following exponentiation, multiplication, division, floor division, modulus, additions and subtractions. If two operators have the same precedence, the expression is evaluated from left to right.
Put parentheses in the following equation, in such a way that the result of the expression is 0.
2 * 4 + 5 - 9 * 2# Code for assignment 1.2
def assignment_1_2():
# YOUR CODE HERE
raise NotImplementedError()
return 2 * 4 + 5 - 9 * 2# Test for assignment 1.2
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_1_2(assignment_1_2)# Assertion for assignment 1.2
check_assertion(assignment_1_2)Assignment 1.3
Help us format this data: Use string manipulation to seperate the names of the participants with a tabstop from the age and have one participant per line!
"Petra11Sophie23Agatha57Adam90Joeri29Timo41Eva27"Expected output:
Petra 11
Sophie 23
Agatha 57
Adam 90
Joeri 29
Timo 41
Eva 27
# Code for assignment 1.3
def assignment_1_3():
# YOUR CODE HERE
raise NotImplementedError()
return "Petra11Sophe23Agatha57Adam90Joeri29Timo41Eva27"# Test for assignment 1.3
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_1_3(assignment_1_3)# Assertion for assignment 1.3
check_assertion(assignment_1_3)Assignment 2.1
Clean this list of participants to only contain participants with uneven numbers as participant ids.
Input
["participant_001", "participant_002", "participant_003", "participant_004", "participant_005", "participant_006", "participant_007", "participant_008", "participant_009"]Expected output:
['participant_001', 'participant_003', 'participant_005', 'participant_007', 'participant_009']# Code for assignment 2.1
def assignment_2_1(list_participants):
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 2.1
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_2_1(assignment_2_1)# Assertion for assignment 2.1
check_assertion(assignment_2_1)Assignment 2.2
Create a list and add three separate dictionaries containing the following data:
id: "p_001"
name: "Peter"
age: 50
occupation: "researcher"
id: "p_002"
name: "Petra"
age: 30
occupation: "PhD"
id: "p_003"
name: "Lisa"
age: 15
occupation: "student"
# Code for assignment 2.2
def assignment_2_2():
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 2.2
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_2_2(assignment_2_2)# Assertion for assignment 2.2
check_assertion(assignment_2_2)Assignment 2.3
Using any of the introduced data collection types, find the (only) name that is in both of these two lists of names.
names1 = ["Lisa", "Lia", "Lissa", "Liia", "Lija", "Pia", "Pina", "Pip"]
names2 = ["Lira", "Liua", "Liaa", "Lina", "Lia", "Pio", "Pima", "Pif"]# Code for assignment 2.3
def assignment_2_3(names1, names2):
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 2.3
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_2_3(assignment_2_3)# Assertion for assignment 2.3
check_assertion(assignment_2_3)Assignment 3.1
Check whether name1 and/or name2 is registered. If the name is registered print the message: <name> registered!.
Note: Use if and elif
Expected input
registered = ["Klaus", "Petra", "Adam", "Michel", "Susanne", "Lisa"]
name1 = "Adam"
name2 = "Peter"Expected output (printed):
"Adam registered!"# Code for assignment 3.1
def assignment_3_1(registered, name1, name2):
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 3.1
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_3_1(assignment_3_1)# Assertion for assignment 3.1
check_assertion(assignment_3_1)Assignment 3.2
Using a loop, check whether each city in the list locations is in randstad, if that is not the case, add it to a new list called “outside”.
Input
locations = ["Amsterdam", "Rotterdam", "Utrecht", "Leiden", "Delft", "Arnhem", "Nijmegen"]
randstad = ["Amsterdam", "Rotterdam", "Leiden", "Delft"]Expected output
['Utrecht', 'Arnhem', 'Nijmegen']# Code for assignment 3.2
def assignment_3_2(locations, randstad):
outside = []
# YOUR CODE HERE
raise NotImplementedError()
return outside# Test for assignment 3.2
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_3_2(assignment_3_2)# Assertion for assignment 3.2
check_assertion(assignment_3_2)Assignment 3.3
Take the dictionary with participants and their attendance and use it to create two seperate lists: One list of all participants that attended and one list of all absent participants.
Expected input
participants = {"p1": "absent", "p2": "participated", "p3": "participated", "p4":"absent", "p5":"participated", "p6":"NA"}Expected output
['p2', 'p3', 'p5'], ['p1', 'p4']# Code for assignment 3.3
def assignment_3_3(participants):
# YOUR CODE HERE
raise NotImplementedError()# Test for assignment 3.3
# Press Ctrl-Enter (PC) or Command-Enter (Mac) after changing the function
# above and pressing Ctrl-Enter (PC) or Command-Enter (Mac)
test_cell_3_3(assignment_3_3)# Assertion for assignment 3.3
check_assertion(assignment_3_3)