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.
Have fun!
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 n=0,1,2,3,4,5,...
The sequence looks like: 0,1,1,2,3,5,8,13,...
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 ____
You are expected to comply with University policies and guidelines namely, Appropriate Use of Information Resources Policy, IT Usage Policy and Social Media Policy. Users will be personally liable for any infringement of Copyright and Licensing laws. Unless otherwise stated, all guide content is licensed by CC BY-NC 4.0.