Question

In: Computer Science

Define a Python function which finds the all of the odd numbers and the product of...

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)

Solutions

Expert Solution

#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)



Related Solutions

Write a Python function which finds the smallest even and odd numbers in a given list....
Write a Python function which finds the smallest even and odd numbers in a given list. (Use for loop and if conditions for this problem)
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The...
Python Exercise 2 A program is to display all odd numbers between 10 and 3000. The starting value and end value are to be assigned by the programmer, not requested from user.
(a) Use a direct proof to show that the product of two odd numbers is odd....
(a) Use a direct proof to show that the product of two odd numbers is odd. (b) Prove that there are no solutions in integers x and y to the equation 2x2 + 5y2 = 14. (c) Prove that the square of an even number is an even number using (a) direct proof, (b) an indirect proof, and (c) a proof by contradiction. Q. 2. Maximum score = 25 (parts (a) 9 points, part (b-i) and (b-ii) 8 points) (a)...
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
using python 3 2. Write a python program that finds the numbers that are divisible by...
using python 3 2. Write a python program that finds the numbers that are divisible by both 2 and 7 but not 70, or that are divisible by 57 between 1 and 1000. 3. Write a function called YesNo that receives as input each of the numbers between 1 and 1000 and returns True if the number is divisible by both 2 and 7 but not 70, or it is divisible by 57. Otherwise it returns False. 4. In your...
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
C++ CODE TO FIND ALL Odd numbers between 1 and 70000.
C++ CODE TO FIND ALL Odd numbers between 1 and 70000.
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence to an element at a higher index. Assumptions and restrictions: The function must return a number. If there is no increasing pair in the sequence, the function should return 0. This may happen for example if the sequence is decreasing, or if it contains fewer than 2 elements. You can assume that the argument...
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the...
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the second highest number from the array. If the highest value occurs more than once, then it is also the second highest (see example). Assume the input array will always have length at least two (so there is always a second highest value). The original array must NOT be modified by this function. Example secondHighest([5,3,8,6,2,7,4]) must return 7, and secondHighest([5,3,8,6,2,7,8]) must return 8. I have...
Use a For loop to compute the sum of all the odd numbers from 1 through...
Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic for zyBook Challenge activity 4.6.1 (Nested loops: Indent text) so that the first line is indented userNum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT