11 Programs
11 Programs
Output:
Enter first number:56
Enter second number:34
First number is larger number
1
5. Program to generate the following pattern using nested loop
6. Program to input the value of x and n and print the sum of the
following series:
1+x+x2+x3+x4+ ............xn
8. Program to input the value of x and n and print the sum of the
following series:
x + x2 +x3 + x4 + ........... xn
2 3 4 n
2
digit = temp %10
sum + = digit **3 # calculate sum of cube of each digit
temp //=10
if num==sum: # sum compared with original number
print(“number is Armstrong number”)
else:
print ( “number is not Armstrong number “)
3
print ( “number is not a palindrome “)
first=0
second=1
print(first)
print(second)
for a in range(1,19):
third= first+second
print(third,end= ‘ ‘)
first,second = second,third
5
print(“The number of lower case letters are =”,lcl)
print(“The number of upper case letters are =”,ucl)
16.
Term 2
16.Input a list of numbers and swap elements at the even location with
the
elements at the odd location.
val =eval(input(“Enter a list:”))
print(“Original list is :”,val)
s=len(val)
if s% 2 !=0:
s=s-1
for i in range(0,s,2):
print(i,i+1))
val[i] , val[i+1] = val [i+1] , val[i]
print(“List after swapping:”,val)
Output:
Enter a list : [ 12 , 23 , 45 ,16,22,34]
Original list is : [ 12 , 23 , 45 , 16 , 22 , 34]
01
23
45
List after swapping : [ 23,12 , 16 , 45 , 34 ,22]
6
16. Input a list/tuple of elements, search for a given element in the
list/tuple.
lst = eval(input(“Enter list: “))
length = len(lst)
element = int(input(“Enter element to be searched for :”))
for i in range(0,length):
if element ==lst[i]:
print(element,”found at index”,i)
break
else:
print(element,”not found in given list”)
17.Input a list of numbers and test if a number is equal to the sum of the
cubes of its digits. Find the smallest and largest such number from the
given list of
numbers.
val=eval(input(“Enter a list:”))
alist = [ ]
s = len(val)
for i in range(s):
num = val[i]
csum = 0
while num:
dig = num% 10
csum += (dig * dig * dig)
num = num //10
if csum ==val[i]:
alist.append(val[i])
print(“Largest number from the given list is ”,max(alist))
print(“Smallest number from the given list is ”,max(alist))
7
mean=sum/length
print(“Given list is :”,lst)
print(“The mean of the given list is ;” ,mean)
8
Enter number 2:4
x raise to the power n is 625.0