#q1(prime number)
def prime(x,y):
s=[]
for i in range(x,y+1):
for n in range(2,i):
if i%n==0:
break
else:
s.append(i)
return s
print(prime(100,200))
#q2(sort element accending order)
l=[10,20,30]
def sort(l):
return sorted(l)
x=sort([90,100,80])
print(x[::-1])
#q3(sort without using sort)
l=[90,100,80]
def sort(l):
k=[]
for i in range(len(l)):
k.append(min(l))
l.remove(min(l))
return k
sort(l)
#q4(fibonachi series)
def fib(z):
x=0
y=1
p=[]
while y<=z:
p.append(y)
x,y=y,y+x
return p
fib(50)
#q5(reverese list)
def rev(l):
new_list = l[::-1]
return new_list
l=[40,50,70]
print(rev(l))
#q6(check string palindrom)
def pal(s):
x=s[::-1]
if s==x:
return 'palindrom'
else:
return 'notpalindrom'
pal('121')
#q7(set of duplicate)
l=[1,2,3,1,2,4,5]
def dup(l):
k=[]
for i in l:
if l.count(i)>1:
if i not in k:
k.append(i)
return k
dup(l)
#q8(count no of occourance)
l=[1,2,3,4,1,2,3,6,7]
def countn(l):
s={}
for i in l:
s[i]=l.count(i)
return s
countn(l)
#q9(count no of word)
l='hi ram'
def word(l):
x=l.split(' ')
return x,len(x)
word(l)
#10(find element present in list or not)
l=[1,2,3,4,5,6,8]
i=int(input('enter no for find:-'))
def find(l):
for a in range(len(l)):
if l[a]==i:
return a,i
print('nt')
find(l)
#11(find all num inside string)
l='a1s2d3f45'
def fi(d):
s=['0','1','2','3','4','5','6','7','8','9']
k=[]
for i in l:
if i in s:
k.append(i)
return k
fi(l)
#12(delete rept string valu)
l='satyam'
s=list(l)
for i in s:
if l.count(i)>1:
s.remove(i)
print(s)
#13(removing duplicate from string)
l='satyam'
def dup(l):
#s=list(l)
p=[]
for i in l:
if i not in p:
p.append(i)
return p
dup(l)
#14(k-1)
l=[1,2,3]
def k1(l):
s=[]
if len(l)<4:
for i in range(len(l)):
s.append(max(l))
l.remove(max(l))
else:
for i in range(4):
s.append(max(l))
l.remove(max(l))
x=sum(s)
return x
k1(l)
#14(k-2)
l=[1,1,2,10,3,1,12]
def k2(l):
s=sum(l)*2
x=max(l)
l.remove(x)
0 Comments