Divide larger number with smaller number in Python
if elif - Question 5
In this question, we will see how to input 2 integers and divide the larger number with the smaller one and display the result in Python programming using the if elif statement. To know more about if elif statement click on the if elif statement lesson.
Q5) Write a program in Python to input 2 integers. If either of the two number is 0, display Invalid input, if it is valid entry, divide the larger number with the smaller number and display the result.
Program
print('Enter 2 numbers')
a=int(input())
b=int(input())
if a==0 or b==0:
print('Invalid input')
elif a>b:
print('Result of division = {:.2f}'.format(a/b))
elif b>a:
print('Result of division = {:.2f}'.format(b/a))
Output
Enter 2 numbers 5 2 Result of division = 2.5