22, ఆగస్టు 2025, శుక్రవారం

lab session 5 for python programming ....................

 



n = 6

# Initialize the factorial variable to 1
fact = 1

# Calculate the factorial using a for loop
for i in range(1, n + 1):
    fact *= i

print(fact)



import math

# Lambda function to calculate square root using math.sqrt()sqrt_lambda_math = lambda x: math.sqrt(x)# Example usagenumber = 25result = sqrt_lambda_math(number)print(f"The square root of {number} using math.sqrt() is: {result}")


program 3

# using lambda with max() function

find_max = lambda a, b, c: max(a, b, c)


result = find_max(10, 5, 8)


print("Maximum Number :", result)


prg4 for filter , lambda concepts

a = [1, 2, 3, 4, 5]


res = list(filter(lambda num: num % 2 == 0, a))

print(res)


output

[2, 4]

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి