Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes

How can I get the rest of the numbers in solution to show up?

Every time I run it -- it comes our to be:

012
10
2

I defined my variables...

I have my 2 for loops as:

for rows in range(rows):
    for columns in range(columns):
         print (abs(rows-columns), end="")
asked in CSC201 Spring 2021 by (1 point)
edited by

2 Answers

+4 votes

Have you indented the second loop?
Also, you forgot adding = between end and ""
Besides, you should change your counting name to another name that shouldn't be the same name as your input variables.
Your code would be

for r in range(rows):
    for c in range(columns):
        print (abs(rows-columns), end="")
answered by (1 point)
edited by
+2

Yes I have indented the second loop

+2 votes

The issue here is a subtle bug.

You are using the same variables for two different purposes, and by reusing those same variable names, their values get changed in ways that you didn't want/expect.

Originally rows refers to the total number of rows to count up to, but then later you use it as the loop variable that does the counting, so the rows variable gets set to 0, then 1, then 2, etc.

Same issue for the columns variable.

A good coding pattern to follow would be to use numThings (plural) to refer to the number of things you're counting up to, and use thing (singular) as the variable that actually does the counting.

for thing in range(numThings):
    ...
answered by (4k points)
+2

Ohhhh ok! Thank you!!!

...