You are on page 1of 5

#3)

#add, delete, update, search and sort stl names using a LIST
stl=[]

while(1):
print("----MENU----
\n1.Insert\n2.Delete\n3.Update\n4.Search\n5.Sort\n6.quit")
ch=int(input("Enter your choice"))
if(ch==1):

x=input("Enter the stl name:")


stl.append(x)
print(stl)

continue
elif(ch==2):
print("list",stl)
x=input("Enter the name to be deleted")
if x in stl:
stl.remove(x)
else:
print("not present")
continue

elif(ch==3):
print(stl)
x=int(input("Enter the position to be modified(position 1 to..."))
if x in range(1,len(stl)):
y=input("Enter the name of the stl")
stl[x]=y
continue
elif(ch==4):
print(stl)
x=input("Enter the element to be searched")
if x in stl:
print(x,"found in the list")
else:
print("not found")
elif(ch==5):
stl.sort()
print(stl)
elif(ch==6):
quit()
else:
print("Invalid choice")
4)list to string conversion

#convert a any list to the particular format


def func1(spam):
count =0
new_string=""
for x in spam:
count =count+1
new_string+= x

if len(spam)==1:
return new_string
elif count!=len(spam)-1:
new_string+=","
if count == len(spam)-1:
new_string+=" and " +spam [len(spam)-1]
return str(new_string)
x=input("Enter the different elements of list separated by space")
li=x.split()
print(func1(li))
5)heart patter printing

def heart(grid):
x=0
y=0
new_string=""
for x in range(0,6):
for y in range(0,9):
new_string+=grid[y][x]
new_string+="\n"
print(new_string)

grid = [['.', '.', '.', '.', '.', '.'],


['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
heart(grid)

You might also like