I have this python program
from itertools import product
import itertools
from array import array
for arr in itertools.product(("A", "B", "C"), repeat = 2):
print(arr)
for l in itertools.product((1, 2, 3), repeat = 2):
print (f"The sum is: {sum(l)}")
When I run it I get
('A', 'A')
('A', 'B')
('A', 'C')
('B', 'A')
('B', 'B')
('B', 'C')
('C', 'A')
('C', 'B')
('C', 'C')
The sum is: 2
The sum is: 3
The sum is: 4
The sum is: 3
The sum is: 4
The sum is: 5
The sum is: 4
The sum is: 5
The sum is: 6
Instead I want it to Output the Following
`('A', 'A') The sum is: 2
('A', 'B') The sum is: 3
('A', 'C') The sum is: 4
('B', 'A') The sum is: 3
('B', 'B') The sum is: 4
('B', 'C') The sum is: 5
('C', 'A') The sum is: 4
('C', 'B') The sum is: 5
('C', 'C') The sum is: 6
New contributor
Michael Zangi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2