Week 6
Solutions to Functions and Imports
Exercise 1.1 - Maximal Entertainment
# define function to print out the max value in the list
def print_max_in_list(a_list):
# initialise the current_best to be the first item
current_best = a_list[0]
for item in a_list:
# update the current best if we see a bigger value
if item > current_best:
current_best = item
print("Max Value:" + str(current_best))
# test the function with the following
# expect '376' to be printed
example_list = [4, 9, 376, 12, 234, 124, 94, 3]
print_max_in_list(example_list)Extension 1.1 - Returning max value
Exercise 1.2 - Sum thing to do
Extension 1.2 - Returning Average
Exercise 1.3 - Developing a range of skills
Extension 1.3.1 - Default arguments
Extension 1.3.2 - Recursive Range function
Exercise 2 - Import-ant Syntax
Last updated
Was this helpful?