Luiss
Libera Università Internazionale
degli Studi Sociali Guido Carli
Digital Transformation
and Emerging
Technologies
Coding Lab 9
Exercise 1
Define the function list_intersection that takes two lists as input
and returns a new list containing only the elements that are
common to both lists.
Solution
Exercise 2
Implement the FizzBuzz game. Define a function that takes a number as
input and prints the FizzBuzz sequence (from 1 to the input number, but
print "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz"
for multiples of both.
Example:
input -> 15
output -> 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14,
FizzBuzz
Solution
Exercise 3
• Define a function that takes a list of integers as input.
• The function calculates the maximum and then:
• prints the maximum if the maximum is even
• prints the minimum if the maximum is odd
Solution
Exercise 4
• Define a function that, given a list of strings, checks that among
the elements present there is the word "Luiss" (excluding quotes).
• If present, the function will return the string "yes", otherwise
"no".
Solution
Exercise 5
• Define a function that, given a list of numbers as input, adds 100
to all the negative elements of the list and then returns the
minimum element.
• Example: if the input is [-10, 33, 30, -90, 20, 55] then the
modified list will be [90,33,30,10,20,55] and will be printed 10,
that is the minimum element.
Solution
Exercise 6
• Define a function that given a list of integers as input returns the
square of the fifth element of the input list. If the element does
not exist, the function returns 0.
• For example: if as input I have the list [3,2,1,4,6,5,7] the function
will return 36, i.e., the fifth element (6) raised at the power of 2.
Solution