Create a list which contains the first three odd positive integers and a listbwhich contains the first three even positive integers.a= [1, 3, 5]b= [2, 4, 6]Create a new listcwhich combines the numbers from both lists (orderis unimportant).Find the Maximumvalue in list c (Donot use built-in function)Insert fourth element in listc42Append7,8and9to the end ofc.Print the first twoelements ofc.Print the last element ofbwithout using its length.Print the lengthofa
#creating two lists
a=[1,3,5]
b=[2,4,6]
#creating another list c which is combination of a and b
c=a+b
#finding maximum value in list c
#set max to c[0]
max=c[0]
#loop over c
for i in range(1,len(c)):
#check if c[i]>max
if(c[i]>max):
#set max to c[i]
max=c[i]
#insert 4th element 42 in list
c.insert(3,42)
#append 7,8,9 to c
c.append(7)
c.append(8)
c.append(9)
#printing first 2 elements of c
print("First two elements of list c:",c[0],c[1])
#printing last element of b
print("Last element of list b:",b[-1])
#print length of a
print("Length of list a:",len(a))
Comments
Leave a comment