Visualising factors

后端 未结 1 1621
温柔的废话
温柔的废话 2021-01-29 14:37

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 gi

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 15:22

    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.

    0 讨论(0)
提交回复
热议问题