I am trying to write a program that takes a user input, limit and prints a table to visualise all the factors of each integer ranging from 1 to the limit. Each row represents an integer between 1 and limit, whilst the first row represents the number 1, the second number 2 etc. For a given position i (starting from 1) in a row n, if the i is a factor of the limit then a '*' is there, if not then '-'.
For example for the input of 20 it should produce:
Maximum number to factorise: 20
* - - - - - - - - - - - - - - - - - - -
* * - - - - - - - - - - - - - - - - - -
* - * - - - - - - - - - - - - - - - - -
* * - * - - - - - - - - - - - - - - - -
* - - - * - - - - - - - - - - - - - - -
* * * - - * - - - - - - - - - - - - - -
* - - - - - * - - - - - - - - - - - - -
* * - * - - - * - - - - - - - - - - - -
* - * - - - - - * - - - - - - - - - - -
* * - - * - - - - * - - - - - - - - - -
* - - - - - - - - - * - - - - - - - - -
* * * * - * - - - - - * - - - - - - - -
* - - - - - - - - - - - * - - - - - - -
* * - - - - * - - - - - - * - - - - - -
* - * - * - - - - - - - - - * - - - - -
* * - * - - - * - - - - - - - * - - - -
* - - - - - - - - - - - - - - - * - - -
* * * - - * - - * - - - - - - - - * - -
* - - - - - - - - - - - - - - - - - * -
* * - * * - - - - * - - - - - - - - - *
I currently have:
limit = input('Maximum number to factorise: ')
for i in range(1,int(limit)):
line = '{:2}:'.format(i)
for j in range (1,11):
line += "{:4}".format(i % j)
print(line)
But it gives:
Maximum number to factorise: 20
1: 0 1 1 1 1 1 1 1 1 1
2: 0 0 2 2 2 2 2 2 2 2
3: 0 1 0 3 3 3 3 3 3 3
4: 0 0 1 0 4 4 4 4 4 4
5: 0 1 2 1 0 5 5 5 5 5
6: 0 0 0 2 1 0 6 6 6 6
7: 0 1 1 3 2 1 0 7 7 7
8: 0 0 2 0 3 2 1 0 8 8
9: 0 1 0 1 4 3 2 1 0 9
10: 0 0 1 2 0 4 3 2 1 0
11: 0 1 2 3 1 5 4 3 2 1
12: 0 0 0 0 2 0 5 4 3 2
13: 0 1 1 1 3 1 6 5 4 3
14: 0 0 2 2 4 2 0 6 5 4
15: 0 1 0 3 0 3 1 7 6 5
16: 0 0 1 0 1 4 2 0 7 6
17: 0 1 2 1 2 5 3 1 8 7
18: 0 0 0 2 3 0 4 2 0 8
19: 0 1 1 3 4 1 5 3 1 9
So I have the square but how do I replace the 0s with "*" and everything else with "-"? And how do I get my program to do as asked?