Python Program to find division of two integer numbers

Program

a = int(input('Enter number for a: '))
b = int(input('Enter number for b: '))
if b == 0:
	print("Division by 0 not possible")
else:
	div = a / b
	print('Division = ', format(div))

This Python program takes two numbers as input, performs division, and displays the result. It also handles division by zero.

a = int(input('Enter number for a: '))
b = int(input('Enter number for b: '))
  • input() function takes user input as a string.
  • int() function converts the input to an integer.
  • The user enters two numbers (a and b).
if b == 0:
    print("Division by 0 not possible")
  • Checks if the denominator (b) is zero.
  • If b == 0, division is not possible (to avoid a runtime error).
else:
    div = a / b
    print('Division = ', format(div))
  • Performs division (/) when b is not zero.
  • Prints the result using format(div).

Example Execution:

Case 1: Valid Division

User Input:

Enter number for a: 10  
Enter number for b: 2  

Output:

Division =  5.0  

Case 2: Division by Zero

User Input:

Enter number for a: 10  
Enter number for b: 0  

Output:

Division by 0 not possible  

Key Takeaways:

  1. Handles user input with int(input()).
  2. Checks for division by zero to avoid errors.
  3. Performs division (/) only when b is nonzero.
  4. Displays the result using format().

Output 1

Enter number for a: 23
Enter number for b: 0
Division by 0 not possible

Output 2

Enter number for a: 82
Enter number for b: 3
Division =  27.333333333333332