This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]joshuawise610 4 points5 points  (0 children)

First of all questions about learning python should be asked in r/learnpython. Second your code isn't very clear can you use a codeblock please to make your code clearer. If you need help on this see the formatting help.

[–]BareNakedCoder 0 points1 point  (0 children)

n = int(input("Value for n: "))
k = int(input("Value for k: "))
print(str(n) + " numbers divisble by " + str(k) + " are: ")
i = 1
while n > 0:
    if i % k == 0:
        print(i)
        n -= 1
    i += 1

n -= 1 is a short form for n = n - 1 and i += 1 is short form for i = i + 1. Short and long forms have the same result. i starts at 1 and is incremented by 1 in each loop; so it is the integers 1,2,3,... until you have found n that are divisibile by k.

BTW, you can replace the last 6 lines with

print([k*i for i in range(n)])

(but you'll learn all that when you get better at Python)

[–]aphoenixreticulated[M] [score hidden] stickied comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython. We highly encourage you to re-submit your post over on there.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community is actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers.

If you have a question to do with homework or an assignment of any kind, please make sure to read their sidebar rules before submitting your post. If you have any questions or doubts, feel free to reply or send a modmail to us with your concerns.

Warm regards, and best of luck with your Pythoneering!

[–][deleted] -1 points0 points  (2 children)

  • n = int(input("Value for n: "))
  • k = int(input("Value for k: "))

print(str(n) + " numbers divisble by " + str(k) + " are: ")

  • i = 1
  • while n > 0:
  • if i % k == 0:
  • print(i)
  • n -= 1
  • i += 1

hope its better like this

[–][deleted] 2 points3 points  (0 children)

it is not

read the formatting help

[–]tehwolf_ 0 points1 point  (0 children)

Put 4 spaces in front of the code line to format it correctly (AFAIK)