Python Program to print remainder and quotient

 

Python Program to print remainder and quotient

Write a python program with a single user-defined function called Solve that returns remainder and quotient on the division of two numbers accepted from the user. Print remainder and quotient separately on the console.

Video Tutorial:

Steps to print remainder and quotient

1. First define a method called Solve, which accepts two parameters. The Solve method calculates remainder and quotient. Finally, return the remainder and quotient.

2. Use try and except to check whether the user has entered integer numbers or not. If the user has entered anything other than an integer, statements in the except block will be executed.

3. In try block two numbers are read using input statement and converted into integers. They will be stored into x and y.

4. Next, a user-defined method named Solve method is called.

5. Finally, the remainder and quotient are displayed using a print statement.

Source code of Python Program to print remainder and quotient

def Solve(x, y):
    r = x % y
    q = x//y
    return (r, q)
try:
    x = int (input("Enter the first number:"))
    y = int (input("Enter the second number:"))
    r, q = Solve(x, y)
    print ("The remainder is ", r)
    print ("The quotient is ", q)
except: 
    print ("Enter numeric value")

Output:

Case 1:

Enter the first number: 20

Enter the second number: 3

The remainder is 2

The quotient is 6

Case 2:

Enter the first number: 20

Enter the second number: VTU

ValueError: invalid literal for int() with base 10: ‘VTU’

Summary:

This tutorial discusses how to write a Python Program to display remainder and quotient. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.

Leave a Comment

Your email address will not be published. Required fields are marked *

Welcome to VTUPulse.com


Computer Graphics and Image Processing Mini Projects -> Click Here

Download Final Year Project -> Click Here

This will close in 12 seconds