0

Here's for loop I'm trying to work

for page in range(0, 27800, 20):
    print(f'page {page} =====')

If current page is '2', then this code may print out page number as '20'. If current page is '5', code will print '80'.

I want my code to print actual page numbers such as 1,2,3,4,5,6....(not those parameter numbers)

So How I can do that?

2752353
  • 17
  • 5

2 Answers2

2

From your comments I interpret that the third argument can not be changed or removed. My proposal would be:

for page in range(0, 27800, 20):
    print(f'page {(page/20)+1} =====')
Hein
  • 174
  • 1
  • 10
1

What you need to do is remove the third arguemnt u supplied to the range function as that paramter indicates the step, which is what the start paramter will be incremented by each iteration. The step paramter defaults to 1 which is the behaviour you are looking for.

for page in range(0, 27800):
    print(f'page {page} =====')

For further reading on the range function and the parameters which it accepts: range function documentation

CryptoNoob
  • 171
  • 5
  • Thanks for your advice, but I need that 20 arguement (or parameter?). Because a website I'm trying to scrape was coded like that. So I need that 20, but I want to see print like 1, 2, 3. – 2752353 Apr 16 '22 at 12:18