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: