Apr-29-2021, 09:36 AM
Hi guys. I have stumbled on a issue where I can't multiply the elements in a tuple. Lets say we have [(x1, y1),(x2, y2)], I need the output like this: [(x1 * y1), (x2 * y2)]
Here is the code:
Here is the code:
from itertools import product arr = 0 val_x = [] val_y = [] n = int(input('n = ')) def multiply(product, *nums): factor = product for num in nums: factor *= num return factor if __name__ == "__main__": for x in range(n ** 2): for y in range(n ** 2): if y == 0: arr += 1 if arr == 1: val_x.append(bin(x)[2:].zfill(n)) val_y.append(bin(x)[2:].zfill(n)) arr = 0 res = list(product(val_x, val_y)) print(f'Input x,y = {res}') print(f'Output z = {multiply(*res)}')I get the following error: TypeError: can't multiply sequence by non-int of type 'tuple' .