Here are some function exercises for you to apply what you have just learnt.
Templates for the answers have been given so just add on to it! If you don't want to use it that fine too. There are many ways you can write a function to do the same thing.
You have 103 apples and would like to share them with 5 people. Write a function to find the remainder. Hints:
5 % 4 gives remainder when 5 divided by 4
"""return the remaining number of apples after dividing equally"""
Write a recursive function that will return the nth term of the Fibonacci sequence.
The sequence has a relationship of
Fn = Fn-1 + Fn-2 with
F0 = 0 and
F1 = 1, where
The sequence looks like:
def fibonaci(n): """return the full fibonaci sequence""" if n == 0: return 0 elif n == 1: return 1
Write a function that will count how many odd numbers is present in a given list of integers.
Fill in the function below.
def count_odd_numbers(numbers): count = 0 for i in ____: if ____ % 2 == _____: count += ____ return ____
Write a lambda expression that will cube all the numbers in the list below
num = [1,2,3,4,5,6,7,8]