python
python
Source code:
a=int(input("enter a number"))
t=a
p=0
while a>0:
n=a%10
p=p*10+n
a=a/10
if t==p:
print("number is
palindrome") else:
print("number is not palindrome")
Output:
Program 2:Program to swap two elements from the list
Source code:
a=[1,2,3,4,5,6]
print("values before swap",a)
t=a[4]
a[4]=a[0]
a[0]=t
print("values after swap",a)
Output:
Program 3:To find the second largest number
Source code:
a=[10,20,30,40,50]
b=sorted(a,reverse=True)
sl=b[1]
print(a)
print("second largest in the list is",sl)
Output:
Program 4: To find the index of an item
Source code:
a=[2,3,4,5,7,6,9]
b=a.index(5)
print(a)
print("index of number is",b)
Output:
Program 5: Wap to find the sum and average of list items
Source Code:
L = [4, 5, 1, 2, 9, 7, 10, 8]
count = 0
for i in
L:
count += i
avg = count/len(L)
print("sum = ", count)
print("average = ", avg)
Output:
Program 6: Consider a number entered by a user.Now calculate the factorial of this number.
Source Code:
num = 7
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is
1") else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:
Program 7: Wap to print the fibonacci sequence upto the range entered by user.
Source Code:
Output:
Program 8: Wap to check whether a number entered by the user is a perfect number or not.
Source Code:
Output: