0

I'm working on a practice problem that says, "Make a function that receives an integer as an argument (step) and that prints the numbers from 0 to 100 (included), but leaving step between each one. Two versions: for loop and a while loop.

I can do it using a foor loop:

def function(x):
    count = 0
    for x in range(0, 100, x):
        print(x)

I can't seem to make it work with a while loop. I've tried this:

def function(x):
    count = 0
    while count <= 100:
        count += x
        print(count)

so please, help. Thank you!

3
  • 2
    move count+=x after print Commented Nov 29, 2021 at 19:12
  • In the while version, you should print before you increase the step. Also, you don't need count = 0 in the for version. Commented Nov 29, 2021 at 19:13
  • True! Thank you! Commented Nov 29, 2021 at 19:33

1 Answer 1

1

You need to increment count after printing.

def function(x):
    count = 1
    while count <= 100:
        print(count)
        count += x
Sign up to request clarification or add additional context in comments.

1 Comment

Done with count = 0. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.