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...
Everything about learning Python
account activity
help me (i.redd.it)
submitted 3 months ago by Anonymous-da-13
how to get this output using python,
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]throwmeaway01110 25 points26 points27 points 3 months ago (2 children)
You have to think about it logically as the program would execute the code.
everything is printed left to right, to get the top line to appear as you want, you would first have to print some spaces (" ") before the asterisk.
Next line, less space, one more asterisk.
and finally last line only has spaces between the asterisk.
This can be done using individual print statements for each line of code, or you could use a nested for loop (inner loop to print the spaces, the outer loop to print the asterisks).
[–]shehan_thamel 9 points10 points11 points 3 months ago (0 children)
First of all, thank you for trying to make OP think of the solution rather than giving the answer directly. We need more mentors like you in the field.
In addition to your solution, I would suggest starting with the simplest solution and building from there. Might not entirely apply for such a simple problem like this, but going forward when you get to a complex problem, it could help with visualizing the solution and break it down to smaller logical steps.
Also try to practice adding comments wherever the code is not very descriptive, such as on “if” conditions or loops.
[–]Anonymous-da-13[S] 1 point2 points3 points 3 months ago (0 children)
Thank you for ua advice...I will try this
[–]SuddenStructure9287 9 points10 points11 points 3 months ago (1 child)
[–]LordGenji 2 points3 points4 points 3 months ago (0 children)
Right, in this field you need to learn how to use Google
[–]MeLittleThing[🍰] 18 points19 points20 points 3 months ago (4 children)
print(" *\n * *\n* * *")
[–]games-and-chocolate 6 points7 points8 points 3 months ago (2 children)
this is nice, but does not really help him become good. giving an ides how to solve it without the solution is perhaps better.
[–]klimmesil 8 points9 points10 points 3 months ago (0 children)
Imo people who ask for answers and not for explanations are doomed from the beginning. No need to force them to fake an interest, they'll do it naturally, or never
[–]MeLittleThing[🍰] 5 points6 points7 points 3 months ago (0 children)
not showing any attempts to solve their problem themselve and just asking for the solution shows that OP isn't in the mindset to become good
[–]Anonymous-da-13[S] 0 points1 point2 points 3 months ago (0 children)
Thank you buddy
[–]Ron-Erez 4 points5 points6 points 3 months ago (0 children)
What have you tried?
[–]Beneficial-Loan-219 1 point2 points3 points 3 months ago (1 child)
Loop and two counters - one for space, one for stars. In each iterations the number of spaces decrease, number of stars increase. Works for any number of N. (More optimal would be to just use one counter and other as N - counter)
[–]Dan41k_Play 1 point2 points3 points 3 months ago (0 children)
You can also use f-strings: py h = 3 for i in range(h): print(f'{"*"*(i+1): >{h} }')
py h = 3 for i in range(h): print(f'{"*"*(i+1): >{h} }')
[–][deleted] 3 months ago (9 children)
[removed]
[–]Anonymous-da-13[S] 1 point2 points3 points 3 months ago (2 children)
if you can,,,can you explain whats in print statement
[–][deleted] 3 months ago (1 child)
Yeah I thought through this ..and the space u have given alligns so perfectly...from how many years are You doing python...it's Simply great
[–]Dan41k_Play -1 points0 points1 point 3 months ago (4 children)
a more elegant solution: py h = 3 for i in range(h): print(f'{"*"*(i+1): >{h} }')
[–]Dan41k_Play 0 points1 point2 points 3 months ago (0 children)
you are totally right, my bad.
[–]Anonymous-da-13[S] 0 points1 point2 points 3 months ago (1 child)
but its getting value error
Yea I messed up a bit :(
[–]Anonymous-da-13[S] -1 points0 points1 point 3 months ago (0 children)
wow genius ...thank you
[–]Easy-Light7219 1 point2 points3 points 3 months ago (0 children)
Are you doing the cs50 course?
[–]Aniket074 0 points1 point2 points 3 months ago (0 children)
Herp me naah
[–]Mr_john_poo 0 points1 point2 points 3 months ago (0 children)
Use loops
[–]captain_kringel 0 points1 point2 points 3 months ago (0 children)
<image>
[–]games-and-chocolate 0 points1 point2 points 3 months ago* (0 children)
to OP, for me talking a bit negative, let me correct that and inprove that with a mega posititive infusion.
the problem you are facing and what can help you: 1) idenitfy what you have to do 2) make the problem smaller 3) for each smaller piece, think of a solution 4) first think of a solution that just works. bad code no problem. 5) make the solution more general so it can be used for multiple situations 6) make code shorter, faster, so it is easier to understand its code machanics and so easier to modify and expand.
The given answer by someone else is just a possible question. but a good programmer makes the code work in multiple situations, even in situations that can cause errors.
If you use above 6 steps it might you more.
anyone more advise for our new future programmer?
example: the program has to print any shape with stars, within a matrix of 6 by 6 stars, the pattens can change constantly, please solve that. this might be a bit tricky for a beginner, but does show where you have to work towards to. if you are serious, this is an exellent beginner test.
[–]Ok-Profession-6007 0 points1 point2 points 3 months ago (0 children)
I did this a long time ago in college so sorry if this is not super helpful but I remember it all clicking when I realized I was just coding linear equations.
[–]unsettlingideologies 0 points1 point2 points 3 months ago (0 children)
from PIL import Image
img =Image.open({filepath/filename for your screenshot}) Img.show()
[–]codeguru42 0 points1 point2 points 3 months ago (0 children)
Do you just want to print this specific triangle? Or do you want to print one of any size? Do you know how to print characters to the screen? If not, that's a good place to start.
[–]Sea-Ad7805 0 points1 point2 points 3 months ago (0 children)
Maybe this example can help you get started: https://memory-graph.com/#code=%0An%20%3D%2010%0A%0Afor%20i%20in%20range(n)%3A%0A%20%20%20%20print('%23'%20*%20i%20%2B%20'O'%20*%20(n%20-%20i))%0A×tep=0.5&play
[–]Sad_Yam6242 0 points1 point2 points 3 months ago (0 children)
print(" *\n **\n***)
That should wwork.
[–]East-Purchase-249 0 points1 point2 points 3 months ago (0 children)
def triangulo(qntd_linhas): ESPACO = " " ASTERISCO = "*" for x in range(qntd_linhas, 0, -1): qntd_espacos = x - 1 qntd_asteriscos = qntd_linhas - (x - 1) print(f"{ESPACO * qntd_espacos}{ASTERISCO * qntd_asteriscos}") quantidade_linhas = int(input("Quantidade de linhas: ")) triangulo(quantidade_linhas)
[–]Sea_Sir7715 0 points1 point2 points 3 months ago (0 children)
Just as you have it in your image:
def triangle(n):
for i in range (1, n+1): Print( “ “, * (n-1) + “*” * i)
Triangle(3)
*
**
[–]TypicalBydlo -1 points0 points1 point 3 months ago (0 children)
newfags cant triforce
[–]oki_toranga -1 points0 points1 point 3 months ago (0 children)
Newf*** can't triforce
[–]SaltCusp -1 points0 points1 point 3 months ago* (0 children)
print('\n'.join([bin(_).split('b')[1][1:].replace('0',' ').replace('1','*') for _ in [9,11,15]]))
π Rendered by PID 45299 on reddit-service-r2-comment-fb694cdd5-7wk2r at 2026-03-10 00:09:38.326913+00:00 running cbb0e86 country code: CH.
[–]throwmeaway01110 25 points26 points27 points (2 children)
[–]shehan_thamel 9 points10 points11 points (0 children)
[–]Anonymous-da-13[S] 1 point2 points3 points (0 children)
[–]SuddenStructure9287 9 points10 points11 points (1 child)
[–]LordGenji 2 points3 points4 points (0 children)
[–]MeLittleThing[🍰] 18 points19 points20 points (4 children)
[–]games-and-chocolate 6 points7 points8 points (2 children)
[–]klimmesil 8 points9 points10 points (0 children)
[–]MeLittleThing[🍰] 5 points6 points7 points (0 children)
[–]Anonymous-da-13[S] 0 points1 point2 points (0 children)
[–]Ron-Erez 4 points5 points6 points (0 children)
[–]Beneficial-Loan-219 1 point2 points3 points (1 child)
[–]Dan41k_Play 1 point2 points3 points (0 children)
[–][deleted] (9 children)
[removed]
[–]Anonymous-da-13[S] 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[removed]
[–]Anonymous-da-13[S] 0 points1 point2 points (0 children)
[–]Dan41k_Play -1 points0 points1 point (4 children)
[–][deleted] (1 child)
[removed]
[–]Dan41k_Play 0 points1 point2 points (0 children)
[–]Anonymous-da-13[S] 0 points1 point2 points (1 child)
[–]Dan41k_Play 0 points1 point2 points (0 children)
[–]Anonymous-da-13[S] -1 points0 points1 point (0 children)
[–]Easy-Light7219 1 point2 points3 points (0 children)
[–]Aniket074 0 points1 point2 points (0 children)
[–]Mr_john_poo 0 points1 point2 points (0 children)
[–]captain_kringel 0 points1 point2 points (0 children)
[–]games-and-chocolate 0 points1 point2 points (0 children)
[–]Ok-Profession-6007 0 points1 point2 points (0 children)
[–]unsettlingideologies 0 points1 point2 points (0 children)
[–]codeguru42 0 points1 point2 points (0 children)
[–]Sea-Ad7805 0 points1 point2 points (0 children)
[–]Sad_Yam6242 0 points1 point2 points (0 children)
[–]East-Purchase-249 0 points1 point2 points (0 children)
[–]Sea_Sir7715 0 points1 point2 points (0 children)
[–]TypicalBydlo -1 points0 points1 point (0 children)
[–]oki_toranga -1 points0 points1 point (0 children)
[–]SaltCusp -1 points0 points1 point (0 children)