The product of all the elements in the Python list.

Asked 2 years ago, Updated 2 years ago, 15 views

Hello, I'm a student studying Python.

The problem that needs to be solved is, when there are two lists, return the elements in those two lists multiplied by each other.

For example, if a = [1,2], b = [3,4], return 3,4,6,8.

At first, I tried to do fori, jin zip(a,b), and then the elements were circulated one by one, so I could only print three or eight.

I'd really appreciate it if you could tell me how to do it!

python

2022-09-20 19:18

1 Answers

a = [1,2]
b = [3,4]
x_result = []

for anum in a:
    for bnum in b:
        x_result.append(anum * bnum)

print(x_result)


2022-09-20 19:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.