-2

I have a loop which calculates all the prime numbers. The calculation is good but I can't figure out how to print the hash symbols before the number. For example, here is the code I have:

for num in range(MIN, rangeNumber + 1):
    # Print all prime numbers
    if num > 1:
        for i in range(2, num):
            if (num % i) == 0:
                break
        else:
            print(num)

I am trying to figure out how I can print the # sign before the numbers. Here is the output that is expected:

enter image description here

How can I create the for loop?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Arsalan
  • 36
  • 6

2 Answers2

2

For a string of n #'s, just write '#' * n

Frank Yellin
  • 9,127
  • 1
  • 12
  • 22
0

Try this:

n = 3

for i in range(1, n + 1):
    print("#" * i, i)
OUTPUT:
# 1
## 2
### 3
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
Dan
  • 104
  • 7