Description
Today we write a program to find the maximum number given by user.
Program is very easy and simple. There are various method to solve this problem.
Lets get started...
Using if else statement
n = int(input("Enter the First Number : "))
m = int(input("Enter the Second Number : "))
if n >= m:
print(f"{n} is Maximum")
else:
print(f"{m} is Maximum")
'''
Enter the First Number : 5
Enter the Second Number : 8
8 is Maximum
'''
- Take two number from the user and check by the if else (conditional statement).
- that if (n > m), this condition will be true then print n is maximum and otherwise
- print m is maximum
Using max() method in python
n = int(input("Enter the First Number : "))
m = int(input("Enter the Second Number : "))
print(max(n, m), "is Maximum")
'''
Enter the First Number : 5
Enter the Second Number : 8
8 is Maximum
'''
Using lambda function
n = int(input("Enter the First Number : "))
m = int(input("Enter the Second Number : "))
maximum = lambda a, b: a if a > b else b
print(maximum(n, m), "is Maximum")
'''
Enter the First Number : 5
Enter the Second Number : 8
8 is Maximum
'''
Using Ternary Operator
n = int(input("Enter the First Number : "))
m = int(input("Enter the Second Number : "))
maximum = n if n > m else m
print(maximum, "is Maximum")
'''
Enter the First Number : 5
Enter the Second Number : 8
8 is Maximum
'''