Program 1- Arrangement of Plants
n=int(input())
id1=list()
h=list()
for i in range(n):
id1.append(int(input()))
h.append(int(input()))
for i in range(n):
for j in range(n-i-1):
if(h[j]>h[j+1]):
temp=h[j]
h[j]=h[j+1]
h[j+1]=temp
temp=id1[j]
id1[j]=id1[j+1]
id1[j+1]=temp
for i in range(n):
print(id1[i])
Program 2- Create List and Search
n=int(input())
l=[]
for j in range(n):
b=input().rstrip()
f=0
for i in range(len(l)):
if l[i]==b:
f=1
break
if f==0:
l.append(b)
r=input()
print(l)
if r in l:
print("Found")
else:
print("Not found")
Program 3-Finding Friends
n=[]
while(1):
a=input().rstrip()
if a=="Stop":
break
n.append(a)
index=0
for i in range(len(n)):
if len(n[i])>len(n[index]):
index=i
print(len(n))
print(n[index])
print(len(n[index]))
Program 4- Polynomial Addition
n1=int(input())
l1=[]
for i in range(n1+1):
l1.append(int(input()))
n2=int(input())
l2=[]
for i in range(n2+1):
l2.append(int(input()))
if n1<n2:
while(len(l1)<len(l2)):
l1.insert(0,0)
elif n1>n2:
while(len(l2)<len(l1)):
l2.insert(0,0)
l=[]
for i in range(len(l1)):
l.append(l1[i]+l2[i])
print(l)
Program 5- Sparse Matrix
import sys
r=int(input())
c=int(input())
if(r<1 or c<1):
print('Invalid input')
sys.exit()
c1=0
c2=0
matrix=[]
for i in range(r):
matrix.append([])
for j in range(c):
matrix[i].append(int(input()))
if matrix[i][j]==0:
c1+=1
else:
c2+=1
if(c1>=c2):
print("Sparse")
else:
print("Not sparse")
Try my app on play store and rate it!
App link- https://play.google.com/store/apps/details?id=appinventor.ai_mayanktechnologies09.Translator
No comments:
Post a Comment