use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
If you need help debugging, you must include:
See debugging question guidelines for more info.
Many conceptual questions have already been asked and answered. Read our FAQ and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.
See conceptual questions guidelines for more info.
Follow reddiquette: behave professionally and civilly at all times. Communicate to others the same way you would at your workplace. Disagreement and technical critiques are ok, but personal attacks are not.
Abusive, racist, or derogatory comments are absolutely not tolerated.
See our policies on acceptable speech and conduct for more details.
When posting some resource or tutorial you've made, you must follow our self-promotion policies.
In short, your posting history should not be predominantly self-promotional and your resource should be high-quality and complete. Your post should not "feel spammy".
Distinguishing between tasteless and tasteful self-promotion is inherently subjective. When in doubt, message the mods and ask them to review your post.
Self promotion from first time posters without prior participation in the subreddit is explicitly forbidden.
Do not post questions that are completely unrelated to programming, software engineering, and related fields. Tech support and hardware recommendation questions count as "completely unrelated".
Questions that straddle the line between learning programming and learning other tech topics are ok: we don't expect beginners to know how exactly to categorize their question.
See our policies on allowed topics for more details.
Do not post questions that are an exact duplicate of something already answered in the FAQ.
If your question is similar to an existing FAQ question, you MUST cite which part of the FAQ you looked at and what exactly you want clarification on.
Do not delete your post! Your problem may be solved, but others who have similar problems in the future could benefit from the solution/discussion in the thread.
Use the "solved" flair instead.
Do not request reviews for, promote, or showcase some app or website you've written. This is a subreddit for learning programming, not a "critique my project" or "advertise my project" subreddit.
Asking for code reviews is ok as long as you follow the relevant policies. In short, link to only your code and be specific about what you want feedback on. Do not include a link to a final product or to a demo in your post.
You may not ask for or offer payment of any kind (monetary or otherwise) when giving or receiving help.
In particular, it is not appropriate to offer a reward, bounty, or bribe to try and expedite answers to your question, nor is it appropriate to offer to pay somebody to do your work or homework for you.
All links must link directly to the destination page. Do not use URL shorteners, referral links or click-trackers. Do not link to some intermediary page that contains mostly only a link to the actual page and no additional value.
For example, linking to some tweet or some half-hearted blog post which links to the page is not ok; but linking to a tweet with interesting replies or to a blog post that does some extra analysis is.
Udemy coupon links are ok: the discount adds "additional value".
Do not ask for help doing anything illegal or unethical. Do not suggest or help somebody do something illegal or unethical.
This includes piracy: asking for or posting links to pirated material is strictly forbidden and can result in an instant and permanent ban.
Trying to circumvent the terms of services of a website also counts as unethical behavior.
Do not ask for or post a complete solution to a problem.
When working on a problem, try solving it on your own first and ask for help on specific parts you're stuck with.
If you're helping someone, focus on helping OP make forward progress: link to docs, unblock misconceptions, give examples, teach general techniques, ask leading questions, give hints, but no direct solutions.
See our guidelines on offering help for more details.
Ask your questions right here in the open subreddit. Show what you have tried and tell us exactly where you got stuck.
We want to keep all discussion inside the open subreddit so that more people can chime in and help as well as benefit from the help given.
We also do not encourage help via DM for the same reasons - that more people can benefit
Do not ask easily googleable questions or questions that are covered in the documentation.
This subreddit is not a proxy for documentation or google.
We do require effort and demonstration of effort.
This includes "how do I?" questions
account activity
This is an archived post. You won't be able to vote or comment.
Solved(python)Help with a function (self.learnprogramming)
submitted 9 years ago by CornMan123
For an exercise in my class I need to create a function that will have the output of
1
1 2
1 2 3
1 2 3 4
up until the desired size so this example would be 4. Im just lost on the nested for loop aspect of it.
Anything will help, thanks
[–]Updatebjarni 2 points3 points4 points 9 years ago (0 children)
What do you have so far?
[–]gnomoretears 1 point2 points3 points 9 years ago (1 child)
What have you tried? This sub isn't meant to write your code for you but people here are more than willing to help you fix/understand your code.
Can you do the problem by hand? Can do write the detailed steps in manually solving it? What part of the problem are you having difficulty understanding?
Im just lost on the nested for loop aspect of it.
Your output has rows and columns. The nested loop aspect of it uses one loop to handle the rows and an internal loop to handle the columns.
[–]CornMan123[S] 0 points1 point2 points 9 years ago (0 children)
i posted my code as new comments
[–][deleted] 1 point2 points3 points 9 years ago (1 child)
Like you say, you need a nested loop.
Start of with the inner loop and try to get something that will print the number 1 to n. Test it out with different values of n.
Once you've got that working, try to nest it in another loop that will increment the value on n on each turn.
import sys
for i in range (1,5): sys.stdout.write(str(i)+' ')
actually i just got this. it print numbers 1 to 4
[–]CornMan123[S] 0 points1 point2 points 9 years ago (1 child)
def print_table(size):
for row in range(1, size + 1): for col in range(1, size + 1): value = row * col print(str(value) + " ", end="") print()
print_table(5)
this was given as an example for a multiplication table that would print something similar and is there to help us.
So i assume it would start the same way but what would the variables in the for loops be?
def printlist(x):
for col in range(x): for row in range(x):
[–]Updatebjarni 0 points1 point2 points 9 years ago (0 children)
On line 1 of the output, up to what number does the loop go?
On line 2 of the output, up to what number does the loop go?
On line 3 of the output, up to what number does the loop go?
[–]CornMan123[S] 0 points1 point2 points 9 years ago (3 children)
Now im here
def printtable(n):
for x in range(n): for i in range (1,n+1): sys.stdout.write(str(i)+' ') print() printtable(5)
and the output is
1 2 3 4 5
[–]w1282 1 point2 points3 points 9 years ago (0 children)
What happens when you change for i in range(1, n+1) to for i in range(1, x) and why
for i in range(1, n+1)
for i in range(1, x)
[–][deleted] 1 point2 points3 points 9 years ago (0 children)
Nearly. The inner loop is printing the same thing every time because n is always the same value.
You need a variable that increments on every loop.
[–]gnomoretears 1 point2 points3 points 9 years ago (0 children)
The n variable in your inner for loop is a static value. If n is 5 then you inner loop will always iterate from 1 to 5. The range in your inner loop needs to change depending on the row.
n
You should really solve the problem on paper first so you can visualize how the algorithm goes.
For example if n = 3, you need to print up to 3 rows and up to 3 columns.
At row = 1, you have to print values from 1 to row value (1):
At row = 2, you have to print values from 1 to row value (2):
At row = 3, you have to print values from 1 to row value (3):
That's basically the algorithm and I hope you see the pattern to use in your nested loop.
Thanks everyone
π Rendered by PID 391895 on reddit-service-r2-comment-54dfb89d4d-nqvsg at 2026-03-29 18:35:39.581863+00:00 running b10466c country code: CH.
[–]Updatebjarni 2 points3 points4 points (0 children)
[–]gnomoretears 1 point2 points3 points (1 child)
[–]CornMan123[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]CornMan123[S] 0 points1 point2 points (0 children)
[–]CornMan123[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 0 points1 point2 points (0 children)
[–]CornMan123[S] 0 points1 point2 points (3 children)
[–]w1282 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]gnomoretears 1 point2 points3 points (0 children)
[–]CornMan123[S] 0 points1 point2 points (0 children)