Skip to content Skip to sidebar Skip to footer

Visualising Factors

I've come across a problem that asks me to print a table to visualize all factors of each integer ranging from 1 to limit. Then it specifies that a given position i, starting from

Solution 1:

I am not going to give the complete code, since this is clearly an homework assignment.

But here is a pseudo algorithm that can get you started -

  1. You would need two for loops, one nested inside the other. The first for loop for going over the rows, second inner for loop for going over the columns.

  2. Inside the nested for loop, you would need to check whether the counter for inner for loop is divisible by the counter variable of the outer for loop, if it is you need to print * without giving a new line (To do this you can use end='' argument in Python 3 , or use , after what you want to print in Python 2), if not divisible print -.

  3. Finally after completing the inner loop, you would need to print another newline, so that the next row starts at next line.

Post a Comment for "Visualising Factors"