#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ENGG1811 Lecture Week 6 Multiple default argument """ # A function to print two numbers in either ascending or # descending order. It also has an option to print the # the numbers entered by the user def arrange(num1, num2, order = 'ascending', print_orig = False): # big <- bigger number # small <- smaller number if num1 >= num2: big, small = num1, num2 else: big, small = num2, num1 # Print in ascending or descending # order depending on the input if print_orig: print('Original values:',num1,num2) if order == 'ascending': print(order,':',small, big) elif order == 'descending': print(order,':',big, small) else: print('Invalid option') #%% # All the calling methods give the same result arrange(10, 7) arrange(10, 7, 'ascending') arrange(10, 7, 'ascending', False) #%% All the calling methods give the same result # The second calling method is the interesting one # By using keyword argument, you can skip the default arrange(10, 7, 'ascending', True) arrange(10, 7, print_orig = True) # Note: The will NOT work: arrange(10, 7, True) #%% Try this too # arrange(10, 7, print_orig = True, order = 'descending')