Tuesday, August 25, 2020

Python Program Solution Sumita Arora Text Book Unsolved Based on List Concept .

LIST program s
In [ ]:
#11c1reverse an array of integer or sequence of integer
s=[12]
while True:
    n=input('enter list element or enter x for exit')
    if(n=='x'):
       break;
    s.append(n)    
print(s)
rs=s[len(s)-1::-1]
print(rs)
In [ ]:
#11c9b sum number's list element with a new integer num1
s=input('enter string');
rv=s[len(s)-1::-1]
if(s==rv):
   print('string is palindrome')
else:
   print('string is not a palinrome')
In [ ]:
#11c8 fibbonacci sequence generator
s=int(input('enter length of fibbonacci sequence'))
a=0
b=1
fl=[]
for i in range(1,s+1):
    
      if(i==1):
          fl.append(a)
      elif(i==2):
          fl.append(b)
      else:
          c=a+b
          fl.append(c)
          a=b
          b=c
print(fl)
In [ ]:
#11c7program to rorate list clock wise ,first element to second ,second to third
#n so on...
s=list(eval(input('enter list please')))
ns=[]
if(len(s)%2==0):
    ns+=s[len(s)//2:]
    ns+=s[0:len(s)//2]
else:
    ns+=s[len(s)//2+1:]
    ns.append(len(s)//2+1)
    ns+=s[0:len(s)//2]
print(s)
print(ns)
In [ ]:
#11c6 program to sum two list's individual element and form a new list
L1=list(eval(input('enter list1')))
L2=list(eval(input('enter list2')))
L3=[]
if(len(L1)<len(L2)):
    for i in range(len(L1)):
        L3.append(L1[i]+L2[i])
    L3+=L2[len(L1):len(L2)]
    print(L3)
if(len(L1)>len(L2)):
    for i in range(len(L2)):
        L3.append(L1[i]+L2[i])
    L3+=L1[len(L2):len(L1)] 
    print(L3)
In [ ]:
#11c4 program to enter a list containig string,
#remove first character from each string.
p=list(eval(input('enter list')))
tl=0
pos=0
for i in range(len(p)):
    if(tl<len(p[i])):
         tl=len(p[i])
         pos=i
    
print(p)
print('max length string is',tl,'and string is',p[pos])
In [ ]:
#11c5a;using for loop create list for sqare of integer 1 to 50
lis=[]
for i in range(1,51):
    lis.append(i*i)
print(lis)
In [ ]:
#11c5c list like a,bb,ccc,dddd........z26 time
lis=[]
ch=97
for i in range(1,26):
    lis.append(chr(ch)*i)
    ch+=1
print(lis)
In [ ]:
#11c5a;using for loop create list for sqare of integer 1 to 50
lis=[]
for i in range(1,51):
    lis.append(i*i)
print(lis)
In [ ]:
#11c4 program to enter a list containig string,
#remove first character from each string.
p=list(eval(input('enter list')))
for i in range(len(p)):
    p[i]=p[i][1:]
print(p)
In [ ]:
#11c3 ask user to enter list of number between 1 to 12 ,replace all number greater than10
#by 10
lis=list(eval(input('enter list element ')))
for i in range(len(lis)):
    if(lis[i]>10):
       lis[i]=10

print(lis)
In [ ]:
#11c1reverse an array of integer or sequence of integer
s=[12]
while True:
    n=input('enter list element or enter x for exit')
    if(n=='x'):
       break;
    s.append(n)    
print(s)
rs=s[len(s)-1::-1]
print(rs)
In [ ]:
#11c2program to enter two list and create third that contain all element of
#first followed by second

p=list(eval(input('enter list1')))
q=list(eval(input('enter list2')))
r=p+q
print(r)
       
In [ ]:
#11c3 ask user to enter list of number between 1 to 12 ,replace all number greater than10
#by 10
lis=list(eval(input('enter list element ')))
for i in range(len(lis)):
    if(lis[i]>10):
       lis[i]=10

print(lis)
In [ ]:
#11c4 program to enter a list containig string,
#remove first character from each string.
p=list(eval(input('enter list')))
for i in range(len(p)):
    p[i]=p[i][1:]
print(p)
In [ ]:
#11c5a;using for loop create list for integer 0 to 49
lis=[]
for i in range(50):
    lis.append(i)
print(lis)
In [ ]:
#11c4 program to enter a list containig string,
#remove first character from each string.
p=list(eval(input('enter list')))
tl=0
pos=0
for i in range(len(p)):
    if(tl<len(p[i])):
         tl=len(p[i])
         pos=i
    
print(p)
print('max length string is',tl,'and string is',p[pos])
In [ ]:
#11c6 program to sum two list's individual element and form a new list
L1=list(eval(input('enter list1')))
L2=list(eval(input('enter list2')))
L3=[]
for i in range(len(L1)):
    L3.append(L1[i]+L2[i])
print(L3)
In [ ]:
#11c6 program to sum two list's individual element and form a new list
L1=list(eval(input('enter list1')))
L2=list(eval(input('enter list2')))
L3=[]
if(len(L1)<len(L2)):
    for i in range(len(L1)):
        L3.append(L1[i]+L2[i])
    L3+=L2[len(L1):len(L2)]
    print(L3)
if(len(L1)>len(L2)):
    for i in range(len(L2)):
        L3.append(L1[i]+L2[i])
    L3+=L1[len(L2):len(L1)] 
    print(L3)
In [ ]:
#11c7program to rorate list clock wise ,first element to second ,second to third
#n so on...
s=list(eval(input('enter string')))
ns=[]
ns.append(s[len(s)-1])
ns+=s[0:len(s)-1]
print(s)
print(ns)
In [ ]:
#11c9a print longest string in list of string 
s=list(eval(input('enter string sequence')))

max=0
ms=''
for i in range(len(s)):

       if(len(s[i])>max):
          max=len(s[i])
          ms=s[i]
print(ms)
In [ ]:
#11c9b sum number's list element with a new integer num1
s=list(eval(input('enter string sequence')))

max=0
ms=''
for i in range(len(s)):

       if(len(s[i])>max):
          max=len(s[i])
          ms=s[i]
print(ms)
In [ ]:
#11c9b sum number's list element with a new integer num1
s=input('enter string');
rv=s[len(s)-1::-1]
if(s==rv):
   print('string is palindrome')
else:
   print('string is not a palinrome')
In [ ]:
 

No comments:

Post a Comment