How do I create two columns for two for loops

I’ve been stuck on this for almost 3 hours, I would really appreciate some help.

I basically want the output for the first loop to be on the right and the second one to be on the left.

This is the closest I’ve gotten to it.

PER_CREDIT = 115
INCREMENT = 1.04
YEAR = 2008

for i in range (5):
    PER_CREDIT = PER_CREDIT * INCREMENT
    print ("t","%.2f" % PER_CREDIT)

for i in range (5):
    YEAR = YEAR + 1
    print(YEAR,"t")


  

Answer

Try combining the two loops, and add a label at the start:

PER_CREDIT = 115
INCREMENT = 1.04
YEAR = 2008
print("label1 t label2")
for i in range (5):
    PER_CREDIT = PER_CREDIT * INCREMENT
    YEAR = YEAR + 1
    print ("%.2f t" % (PER_CREDIT), YEAR)

if you want them to switch places (one on the right and the other on the left) simply use:

print (YEAR, "%.2f t" % (PER_CREDIT))

instead of the other print

Leave a Reply

Your email address will not be published. Required fields are marked *