Write a Program That Reads Integers user_num And div_num as Input And Outputs user_num Divided by div_num Three Times Using Floor Divisions

Hi, in this article you will learn about how to perform a  floor division after given integers and print the result.

Let's use Python programming to perform the floor division and print the result.

 

 

Program That Reads Integers user_num And div_num as Input And Outputs user_num Divided by div_num Three Times Using Floor Divisions

 


Write a Program That Reads Integers User_Num And Div_Num as Input And Outputs User_Num Divided by Div_Num Three Times Using Floor Divisions

Let's take two variables named user_num and div_num. user_num and div_num are numerator and denominator respectively. Use the input function call and ask the user to enter numbers and then convert into any Integer using the type conversion.

user_num = int(input("Enter a user_num : "))
div_num = int(input("Enter a div_num : "))





Using the try and except block, try dividing the numerator with the denominator and print the result using the print function call. In the try block use the print statement to print the floor division of two  integer numbers (use integer division method  using double // operator)

In the accept block catch the zero division error and use the print statement to handle the negative scenario that is zero division error.

try:
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
except ZeroDivisionError:
   print("Division by zero impossible")





Python Program
===========================

user_num = int(input("Enter a user_num : "))
div_num = int(input("Enter a div_num : "))

try:
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
   print(f"Floor Division of {user_num} / {div_num} = {user_num // div_num }")
except ZeroDivisionError:
   print("Division by zero impossible")







Output
=============
Enter a user_num : 8
Enter a div_num : 2
Floor Division of 8 / 2 = 4
Floor Division of 8 / 2 = 4
Floor Division of 8 / 2 = 4




Output
=========================
Enter a user_num : 8
Enter a div_num : 0
Division by zero impossible

 

 

Output
======================
Enter a user_num : 90000
Enter a div_num : 45
Floor Division of 90000 / 45 = 2000
Floor Division of 90000 / 45 = 2000
Floor Division of 90000 / 45 = 2000






Conclusion
================
Execute the above Python program by providing the random integer values as an input to it. Perform the floor division after numbers and note down the result.

Comment below if you have any suggestions to improve the above  Python program.





Post a Comment

0 Comments