Python : Program to find maximum number – Exploring max()

Hello Friends,
Today in this article we are going to discuss that how to find maximum number in Python using max() function
What is max() function?
Python max() function returns the largest item in an iterable or the largest of two or more arguments
Syntax:
1, num2, *num [, key])
Example
num1 = 4
num2 = 8
num3 = 2
max_num = max(num1, num2, num3)
print(max_num)
----------------------------------------
In[1] runfile(...)
8
What is append() function in Python?
append() function in python that adds a single item to the existing list.
Syntax:
list.append(item)
Example
currencies = ['Dollar', 'Euro', 'Pound']
currencies.append('Yen')
print(currencies)
-----------------------------------------------
In[1] runfile(...)
['Dollar', 'Euro', 'Pound', 'Yen']
Program to determine maximum number from the given numbers
Creating a empty list
numbers = []
Asking number of elements from which we need to find the maximum number and add to list
count = int(input("Among how many number do you want to find")
Reading the numbers
for icounter in range(1, count + 1):
digits = int(input("Enter digits: "))
append() function is method in python that adds a single item to the existing list.
numbers.append(digits)
print maximum number using max() function
print("Largest digit is:", max(numbers))
Full code
# Program to determine maximum number from the given numbers
# Creating a empty list
numbers = []
# asking number of elements to put in list
count = int(input("Amoung how many number do you want to find"))
# Reading the numbers
for icounter in range(1, count + 1):
digits = int(input("Enter digits: "))
# append() function is method in python that adds a single item to the existing #list.
numbers.append(digits)
# print maximum number using max() function
print("Largest digit is:", max(numbers))
-----------------------------------------------------------------------------------
In[1] runfile(...)
Amoung how many number do you want to find: 3
Enter digits: 7
Enter digits: 9
Enter digits: 3
Largest digit is: 9
We have very good series of Python articles, please have a look –
Thank you
Have a nice day 🙂
You must log in to post a comment.