-2

I have to count till 45 with increments of 3 using for loop only in python. I did it using while loop but I want to do it without the while loop?

for n in range(1):
    while n < 45:
        n = n + 3
        print(n)
1
  • 1
    It seems you didn't find the documentation for range. Here it is. Commented Oct 8, 2022 at 6:32

1 Answer 1

0

Use the range function with start stop and step parameters

for i in range(3,46,3):
    print(i)

OUTPUT

3
6
9
12
15
18
21
24
27
30
33
36
39
42
45
Sign up to request clarification or add additional context in comments.

2 Comments

I think OP wants to start from 3. So use range(3,46,3)
@codester_09 that would make more sense... I changed it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.