Python Code Examples as Functions
1. Arithmetic Operations
def arithmetic_operations(x, y):
return {
"add": x + y,
"subtract": x - y,
"multiply": x * y,
"divide": x / y if y != 0 else "undefined"
}
2. Data Type Checker
def check_data_types(val):
return type(val)
3. Boolean Comparison
def boolean_comparison(a, b):
return {
"a_less_b": a < b,
"b_less_a": b < a,
"a_equals_b": a == b,
"a_not_equal_b": a != b
}
4. List Operations
def manipulate_list():
lst = [25, 23, 98, 78]
[Link](45)
[Link](2, 100)
return lst
5. Math Functions
import math
def math_functions(val):
return {
"sqrt": [Link](val),
"floor": [Link](val),
Python Code Examples as Functions
"ceil": [Link](val),
"power": [Link](val, 2),
"pi": [Link]
}
6. Grade Checker
def grade_checker(percent):
if percent >= 80:
return "A Grade"
elif percent >= 60:
return "B Grade"
elif percent >= 50:
return "C Grade"
elif percent >= 33:
return "D Grade"
else:
return "Fail"
7. String Utilities
def string_utilities(s):
return {
"upper": [Link](),
"lower": [Link](),
"length": len(s),
"replace_best": [Link]("best", "good")
}