#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Week 4 This file finds the maximum in a list of numbers """ # %% import math # we want to use the constant math.inf # Note: math.inf is positive infinity # Any number is less than positive infinity # e.g. 5 < math.inf is True # # We need minus infinity here, which is -math.inf # %% # Define num_list num_list = [4, 2, 6, 12, -3, 17] # %% max_so_far = -math.inf # Initialise to minus infinity for num in num_list: if num > max_so_far: max_so_far = num print('The maximum is:',max_so_far)