Hello Programmers, In this blog post, We will learn to find the Maximum of two numbers in python. We will discuss three different methods to find maximum of two numbers in python. Lets discuss them in detail:-
Example:-
Input :- A= 12 , B= 15
Output :- 15
Input :- num1 = -3, num2 = -9
Output :- -3
1. Simple Program to find Maximum:-
This is the simplest method to find the maximum number from the given two numbers. In this method, we will use if else statement to find the greatest number.
simple.py
OUTPUT
The greatest number is:
18
2. Using Def and user Input Method:-
In this method, we will use the def function to define the greatest function with if else statement in it. Once the function is defined we will now add two number which will take input from user and that you numbers will be defined in the def’s greatest function that was made earlier.
userdef.py
OUTPUT
Enter the value of 1st number : 45
Enter the value of 2nd number : 14
45 is bigger
3. Using Max() Function:-
In this method, we will use max() function to find the maximum of two numbers in python. Firstly we will declare two number of our choice. After declaring the function we will make a variable maximum which will be equal to max(a,b). whenever the maximum variable will be printed it will show the maximum number of both the numbers.
Max.py
OUTPUT
The maximum of both number is: 13
Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible. Till then check out our more blog posts.