In: Computer Science
Define a Python function which finds the all of the odd numbers and the product of the odd numbers. (Use for loop and if conditions for this problem. Do not use existing codes. Use your own codes).(You need to use append function to obtain a list of odd numbers)
#function for finding odd number list and odd numbers
product
def oddnumbersAndOddProduct(lst):
l=len(lst)
prod=1
oddlist=[]
#code for odd numbers
for i in range(l):
if(lst[i]%2!=0):
oddlist.append(lst[i])
#code for odd numbers product
for i in range(len(oddlist)):
prod=prod*oddlist[i]
return oddlist,prod
#main program
lst=[]
size=int(input("Enter size of list:"))
#creating user defined list
for i in range(size):
inpt=int(input("Enter element : "))
lst.append(inpt)
#results values
resList,oddProduct = oddnumbersAndOddProduct(lst)
print("Enterd list : ",lst)
print("odd list : ",resList)
print("odd numbers product : ",oddProduct)