-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
  • 14,486
  • 4
  • 43
  • 54
Arsalan
  • 26
  • 5

2 Answers2

1

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

Frank Yellin
  • 6,522
  • 1
  • 9
  • 20
0

Try this:

n = 3

for i in range(1, n + 1):
    print("#" * i, i)
OUTPUT:
# 1
## 2
### 3
snakecharmerb
  • 36,887
  • 10
  • 71
  • 115
Dan
  • 13
  • 4