Python function to find a distinct pair of numbers whose product is odd from a sequence of integer values.
Topic: Python function to find a distinct pair of numbers whose product is odd from a sequence of integer values.
Solution
def odd_product(nums): for i in range(len(nums)): for j in range(len(nums)): if i != j: product = nums[i] * nums[j] if product & 1: return True return False dt1 = [2, 4, 6, 8] dt2 = [1, 6, 4, 7, 8] print(dt1, odd_product(dt1)) print(dt2, odd_product(dt2)) def sum_of_cubes(n): n -= 1 total = 0 while n > 0: total += n * n * n n -= 1 return total print("Sum of cubes: ", sum_of_cubes(3))
List all Python Programs