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

Python Lab Assignment 7

The document contains a series of Python functions demonstrating various programming concepts, including calculating the area of a rectangle, adding numbers with a lambda function, reversing a string, and computing factorials. It also includes functions for checking palindromes, counting uppercase and lowercase letters, generating Fibonacci numbers, and handling command-line arguments. Each function is accompanied by a print statement displaying the output of its execution.

Uploaded by

Nirbhay Bhamre
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 views4 pages

Python Lab Assignment 7

The document contains a series of Python functions demonstrating various programming concepts, including calculating the area of a rectangle, adding numbers with a lambda function, reversing a string, and computing factorials. It also includes functions for checking palindromes, counting uppercase and lowercase letters, generating Fibonacci numbers, and handling command-line arguments. Each function is accompanied by a print statement displaying the output of its execution.

Uploaded by

Nirbhay Bhamre
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

Name : Nirbhay Manikrao Bhamre

PRN: RMC25MC009

# 1. Function to calculate area of rectangle

def area_rectangle(length, width):

return length * width

print("Area is:", area_rectangle(5, 3))

'''

# 2. Lambda function to add 2 numbers

add = lambda a, b: a + b

print("Sum is:", add(10, 20))

# 3. Reverse a string

def reverse_string(s):

return s[::-1]

print("Reversed string is:", reverse_string("1234abcd"))

# 4. Factorial of a number

def factorial(n):

fact = 1

for i in range(1, n+1):

fact *= i

return fact
print("Factorial is:", factorial(5))

# 5. Module with function to calculate square

def square(n):

return n * n

print("Square is:", square(4))

# 6. Function within function (multiplication)

def multiply(a, b):

def inner(x, y):

return x * y

return inner(a, b)

print("Multiplication is:", multiply(4, 5))

# 7. Check palindrome

def is_palindrome(s):

return s == s[::-1]

print("Is palindrome:", is_palindrome("madam"))

# 8. Count upper and lower case

def count_case(s):
upper = 0

lower = 0

for ch in s:

if [Link]():

upper += 1

elif [Link]():

lower += 1

return upper, lower

u, l = count_case("Hello World")

print("Uppercase:", u, "Lowercase:", l)

# 9. Recursive Fibonacci

def fibonacci(n):

if n <= 1:

return n

return fibonacci(n-1) + fibonacci(n-2)

print("Fibonacci series:", end=" ")

for i in range(6):

print(fibonacci(i), end=" ")

# 10. Command-line arguments addition

import sys

a = int([Link][1])

b = int([Link][2])
print("\nSum from command line is:", a + b)

'''

Output of Questions 1 to 10 ::

[Link] is: 15

[Link] is: 30

[Link] string is: dcba4321

[Link] is: 120

[Link] is: 16

[Link] is: 20

[Link] palindrome: True

[Link]: 2 Lowercase: 8

[Link] series: 0 1 1 2 3 5

[Link] from command line is: 30

You might also like