Find the maximum number from given 2 numbers in python

In this program, we learn to find the maximum number from the given two numbers. We find the maximum number using the 2 methods, in the first we use the if condition, and in the second one we use the max() function.


Find The Maximum Of These Two Numbers 

Step to find the maximum number

  1. First, take the input of integer number from the user.
  2. And then we check the maximum number using the if and else conditions.

Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# take input from the user
a = int(input("Enter First number: ")) 
b = int(input("Enter Second Number: "))

# apply condition to check the maximum number
# first we check that a is maximum than b
if a>b:
    print(a,"is the maximum number")

# second we check that b is maximum than a   
elif b>a:
    print(b,"is the maximum number")

# if above both condition is false then we print that both numbers are equal
else:
    print("Both number is equal")

Output

Enter First number: 3 Enter Second Number: 2 3 is the maximum number


Find the maximum number using the max() function

step to finding the maximum number

  1. First, take the input from the user
  2. Then we use the max() function to find the maximum number
  3. And lastly, print the maximum number.

Program

1
2
3
4
5
6
7
8
9
# take input from the user
a = int(input("Enter First number: ")) 
b = int(input("Enter Second Number: "))

# use max() function to find the maximum number
maximum = max(a,b)

# print the maximum number 
print(maximum,"is the maximum number")

Output

Enter First number: 3 Enter Second Number: 4 4 is the maximum number
Next Post Previous Post
No Comment
Add Comment
comment url