0% found this document useful (0 votes)
4 views5 pages

Python Functions: Palindrome, Sum, Factorial

The document contains a lab assignment for a BCA student that includes functions for checking palindromes, calculating the sum of digits, computing factorials, and finding the average of numbers. It also mentions operations to be performed on lists, tuples, and dictionaries. The assignment demonstrates basic Python programming concepts and functions.
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)
4 views5 pages

Python Functions: Palindrome, Sum, Factorial

The document contains a lab assignment for a BCA student that includes functions for checking palindromes, calculating the sum of digits, computing factorials, and finding the average of numbers. It also mentions operations to be performed on lists, tuples, and dictionaries. The assignment demonstrates basic Python programming concepts and functions.
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

Srushti Vijay Uttarkar.

FY BCA
Division-B

Lab Assignment no.2

Topic:Function , List, Tuple , Dictionary

1. Write function for Following :

A) Palindrome checker function

def is_palindrome(s):
s = str(s)

if s == s[::-1]:
return True
else:
return False

word = input("Enter a word or number: ")


if is_palindrome(word):

✅ It's a palindrome!")
print("

❌ Not a palindrome.")
else:
print("
B) Sum of digit

num = input("Enter Number: ")


sum = 0

for i in num:
sum = sum + int(i)

print(sum)
C) factorial function

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)
D) Simple Python function to calculate the average of given
numbers.

numbers = [1, 2, 3, 4, 5]
total = 0
for num in numbers:
total = total + num
average = total / len(numbers)
print(f"The average of the numbers is: {average}")
2. Lists, tuples and dictionaries, Sets Perform following
Operations on list:

You might also like