1) Write a program to find the sum of Fibonacci series till nth term where n will be user
input
# Ask the user for input
n = int(input("Enter how many terms: "))
# Initialize variables
a=0
b=1
sum = 0
# Loop to calculate Fibonacci terms and their sum
for i in range(n):
sum = sum + a
c=a+b
a=b
b=c
# Print the result
print("Sum of Fibonacci series is:", sum)
2) Write a program to print your name in the pattern where name will be user input and
use slicing to print the string
ARPAN
RPAN
PAN
AN
N
# Get the name from user
name = input("Enter your name: ")
# Loop through each character using slicing and spaces
for i in range(len(name)):
print(" " * (i) + name[i:])
3) Write a program to take a list as an input and and find the max and min element of
the list without using max and min function and calculate the product of the maximum
and minimum value.
# Get list input from user
numbers = input("Enter numbers separated by spaces: ")
# Convert input string to a list of integers
num_list = [int(x) for x in numbers.split()]
# Initialize min and max with the first element
min_val = num_list[0]
max_val = num_list[0]
# Loop through the list to find min and max
for num in num_list:
if num < min_val:
min_val = num
if num > max_val:
max_val = num
# Calculate the product
product = min_val * max_val
# Display results
print("Minimum value:", min_val)
print("Maximum value:", max_val)
print("Product of min and max:", product)
4) Write a program to take a list of string as inputs and reverse each string in the list and
print the list
Eg [“sky”,”blue”,”red”] output [“yks”,”eulb”,”der”]
# Get input from the user
input_list = input("Enter strings separated by spaces: ")
# Convert the input string to a list
string_list = input_list.split()
# Reverse each string using slicing
reversed_list = [s[::-1] for s in string_list]
# Print the reversed list
print("Reversed list:", reversed_list)
5) Write a program to take input of two strings as input and find out and store only the
common elements between the two strings in a 3rd string and print the reverse of
that 3rd string
# Take two strings as input
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
# Initialize the third string to store common characters
common = ""
# Loop through characters in first string
for char in str1:
if char in str2 and char not in common:
common += char
# Reverse the third string
reversed_common = common[::-1]
# Print the result
print("Common characters (reversed):", reversed_common)