Sunday, 29 March 2026

๐Ÿš€ Day 6/150 – Find Remainder of Division in Python


๐Ÿš€ Day 6/150 – Find Remainder of Division in Python

Today we will learn how to find the remainder of a division in Python.

The remainder is the value left after division, and it is commonly used in:

  • Even/Odd checks
  • Cyclic operations
  • Number-based logic

๐Ÿง  Problem Statement

๐Ÿ‘‰ Write a Python program to find the remainder when one number is divided by another.

1️⃣ Using % Operator (Most Common)

The % operator is called the modulus operator, and it gives the remainder.

a = 10 b = 3 remainder = a % b print("Remainder:", remainder)






Output
Remainder: 1

✔ Simple and widely used
✔ Best method for beginners

2️⃣ Taking User Input

Make the program dynamic using user input.

a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print("Remainder:", a % b)




✔ Works for any numbers

✔ Useful in real applications

3️⃣ Using a Function

Functions help in writing reusable code.

def find_remainder(x, y): return x % y print(find_remainder(10, 3))



✔ Clean and reusable
✔ Good programming practice

4️⃣ Using divmod() Function

Python provides a built-in function that returns both quotient and remainder.

a = 10 b = 3 quotient, remainder = divmod(a, b) print("Quotient:", quotient) print("Remainder:", remainder)




Output

Quotient: 3
Remainder: 1

✔ Efficient
✔ Useful when both values are needed

⚠️ Important Note

Division by zero will cause an error:

print(10 % 0) # ❌ Error

Always handle it safely:

if b != 0: print(a % b) else: print("Cannot divide by zero")



๐ŸŽฏ Key Takeaways

Today you learned:

  • Modulus operator %
  • Taking user input
  • Using functions
  • Using divmod()
  • Handling division errors






0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (227) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (28) Azure (9) BI (10) Books (262) Bootcamp (1) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (29) data (5) Data Analysis (28) Data Analytics (20) data management (15) Data Science (333) Data Strucures (16) Deep Learning (137) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (68) Git (10) Google (50) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (41) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (267) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (13) PHP (20) Projects (32) pytho (1) Python (1271) Python Coding Challenge (1103) Python Mistakes (50) Python Quiz (457) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (46) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)