Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 5 :- Write a python program to check if a value entered by a
user is Palindrome or not.
OBJECTIVE :- To check number is palindrome or not.
SOURCE CODE :-
n=0
rev=0
rem=0
temp=0
n = int(input("\nEnter no: to check palindrome\n"))
temp = n
while(n!=0):
rem = n%10
rev = rev*10 + rem
n =n//10
if(temp == rev):
print("\nNumber is Palindrome\n")
else:
print("\nNumber is not Palindrome\n")
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 5:-
Enter no: to check palindrome
525
No: is Palindrome
Enter no: to check palindrome
687
No: is not Palindrome
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 6 :- WAP to swap two elements in a list.
OBJECTIVE :- To swap two elements.
SOURCE CODE :-
print("\nProgram for swapping two no:\n")
a=0
b=0
list1 = [12, 67, 33, 9, 62, 88, 15, 90]
print(list1)
print("\n")
a = int(input("\nEnter position of first no: for swapping\n"))
b = int(input("\nEnter position of second no: for swapping\n"))
list1[a-1], list1[b-1] = list1[b-1], list1[a-1]
print("\nNew list\n")
print(list1)
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 6:-
Program for swapping two no:
[12, 67, 33, 9, 62, 88, 15, 90]
Enter position of first no: for swapping
Enter position of second no: for swapping
New list
[12, 88, 33, 9, 62, 67, 15, 90]
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 7:- Write a Python program to find the second largest number
in a list.
OBJECTIVE :- To find second largest number.
SOURCE CODE :-
list = []
n = int(input("Enter the number of elements in list: "))
for i in range(n):
element = int(input("Enter element {}: ".format(i+1)))
[Link](element)
[Link]()
if len(list)>=2:
print("Second largest number is:",list[-2])
else:
print("There are not enough elements in the list to find the second largest.")
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 7:-
Enter the number of elements in list: 5
Enter element 1: 77
Enter element 2: 2
Enter element 3: 5
Enter element 4: 66
Enter element 5: 9
Second largest number is: 66
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 8 :- Write a Python program to find the index of an item in a
specified list.
OBJECTIVE :- To find index of a number.
SOURCE CODE :-
list = []
n = int(input("Enter the number of elements in list: "))
for i in range(n):
element = int(input("Enter element {}: ".format(i+1)))
[Link](element)
print("\nEnter the no: whos index to be found\n")
print(list)
num = int(input("\nEnter any no: from list\n"))
print("Index is = ",[Link](num) + 1)
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 8:-
Enter the number of elements in list: 5
Enter element 1: 3
Enter element 2: 8
Enter element 3: 1
Enter element 4: 9
Enter element 5: 4
Enter the no: whos index to be found
[3, 8, 1, 9, 4]
Enter any no: from list
Index is = 1
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 1 :- WAP to find the sum and average of list items.
OBJECTIVE :- To find sum and average of list elements.
SOURCE CODE :-
list = []
n = int(input("Enter the number of elements in list: "))
for i in range(n):
element = int(input("Enter element {}: ".format(i+1)))
[Link](element)
print(list)
sum_ele = sum(list)
print("Sum of list elements is = ",sum_ele)
total = len(list)
print("Average of list elements is = ",(sum_ele/total))
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 1:-
Enter the number of elements in list: 3
Enter element 1: 5
Enter element 2: 5
Enter element 3: 5
[5,5,5]
Sum of list elements is = 15
Average of list elements is = 3.0
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 2:- Consider a number entered by a user. Now calculate the
Factorial of this number.
OBJECTIVE :- To calculate factorial of a number.
SOURCE CODE :-
n = int(input("Enter the number to calculate factorial: "))
fact = 1
for i in range(1, n + 1):
fact *= i
print("Factorial =", fact)
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 2:-
Enter the number to calculate factorial: 5
Factorial = 120
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 3:- Write a python program to print the Fibonacci sequence
upto the range entered by a user.
OBJECTIVE :- To calculate Fibonacci series.
SOURCE CODE :-
x1 = 1
x2 = 1
n=0
i=1
n = int(input("Enter number upto series : "))
if(n==0):
print("Should be greater than zero")
elif(n==1):
print(x1)
elif(n==2):
print(x1,x2)
else:
for i in range(1,n+1):
print(x1,end=" ")
y=x1+x2
x1=x2
x2=y
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 3 :-
Enter number upto series : 10
1 1 2 3 5 8 13 21 34 55
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
PROBLEM STATEMENT 4:- Write a python program to check whether the number
entered by the user is a Perfect number or not.
OBJECTIVE :- To find out perfect number.
SOURCE CODE :-
n = int(input("Enter number to check perfect number: "))
for i in range(1,n+1):
if(n%i==0):
print(i)
Name = Priyanshu Negi Course = BCA (4th sem)
Section = A1 Roll No: = 62
OUTPUT 4 :-
Enter number to check perfect number: 28
14
28