138k views
7 votes
. Write a short Python function that takes a sequence of integer values and determines if there is a distinct pair of numbers in the sequence whose product is odd. (1 Point)

User Gdejohn
by
7.5k points

1 Answer

8 votes

Answer:

Step-by-step explanation:

The following code is written in Python and like requested takes a function called odd_number that takes a list of integers as a parameter. It then loops through the list two times, each time calculating the product of the two numbers and returning Yes if the product is an odd number while also including the two numbers from the list that make that product. If there is no odd product in the list the function simply returns No

def odd_product(my_list):

for num1 in range(len(my_list)):

for num2 in range(len(my_list)):

if num1 == num2:

pass

else:

product = my_list.__getitem__(num1) * my_list.__getitem__(num2)

if (product % 2) != 0:

return "Yes, " + str(my_list.__getitem__(num1)) + " and " + str(my_list.__getitem__(num2))

return "No"

User Fqxp
by
6.0k points