0% found this document useful (0 votes)
2 views6 pages

Reusable Code Blocks in Mini Programs

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Reusable Code Blocks in Mini Programs

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

REUSABLE CODE

BLOCKS WITH
FUNCTION IN MINI
PROGRAMS

.
What is reusable code blocks with function

By using reusable
Reusable code blocks
functions, developers can
with function can be
save time and using it
executed multiple times
many times throughout a
from different parts of a
project. This eliminates
program.
redundant coding .
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
PROGRAM: 1 return "Error: Division by zero!"
return a / b
print("Add:", add(5, 3))
print("Subtract:", subtract(10, 4))
print("Multiply:", multiply(6, 7))
print("Divide:", divide(15, 3))
def check_even_odd(number):
if number % 2 == 0:
return f"{number} is Even"

PROGRAM: 2 else:
return f"{number} is Odd"

print(check_even_odd(10))
print(check_even_odd(15))
OUTPUT: 1 OUTPUT: 2
10 is Even
Add:8 15 is Odd
Subtract: 6
Multiply: 42
Divide: 5.0
THANK YOU

You might also like