-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxlist.py
29 lines (26 loc) · 863 Bytes
/
maxlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def maximum(a,b):
'''
OBJECTIVE:- To find the larger number of the two numbers.
INPUT:-
a: 1st number
b:- 2nd number
OUTPUT: Returns the larger number of the two numbers.
'''
#Approach: Compare the two numbers by using if statement. i.e. a>=b then return a else b
if a>=b:
return a
return b
def maxlist(list1):
'''
OBJECTIVE:- To find the largest number in the list.
INPUT:-
list1:- Input of List of numbers.
OUTPUT:- Returns the largest number from the list.
'''
#Approach: Recursive use of maximum(a,b) function to compare two elements of the list and recusrsively check for rest
if len(list1)==0:
return "List is empty"
if len(list1)==1:
return list1[0]
else:
return maximum(list1[0],maxlist(list1[1:]))