0

My homework assignment is to Loop over ((1, 1), (2, 2), (12, 13), (4, 4)) and use string formatting to display this tuple as:

1 = 1 x 1  
4 = 2 x 2
156 = 12 x 13 
16 = 4 x 4

while also preserving the spacing.

What I have so far:

d = ((1,1), (2,2), (12,13), (4,4))
for a, b in d:
    print("{0} = {1}".format(a* b, d))

Which gives me:

1 = ((1, 1), (2, 2), (12, 13), (4, 4))
4 = ((1, 1), (2, 2), (12, 13), (4, 4))
156 = ((1, 1), (2, 2), (12, 13), (4, 4))
16 = ((1, 1), (2, 2), (12, 13), (4, 4))

So it seems to me that I am getting close. But I have run out of ideas to get the right side of the equation into the correct format. Any ideas would be greatly appreciated.

2 Answers 2

3
d = ((1,1), (2,2), (12,13), (4,4))
for a, b in d:
    print("{0} = {1} x {2}".format(a* b, a, b))
Sign up to request clarification or add additional context in comments.

Comments

1

On the right side of the equation you want to print the content of variable a, then the character x and then the content of variable b.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.