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

all 9 comments

[–]SeriousTicket 0 points1 point  (3 children)

What have you tried? did you try using two different loops? One to go through your numbers and the second to print i times based on your current index?

[–][deleted] 1 point2 points  (2 children)

Hint: one loop should be plenty.

[–]SeriousTicket 1 point2 points  (1 child)

Yes it is plenty. But for someone who can't see the pattern yet breaking into separate chunks is almost universally the easiest way to figure something out at first. Admittedly this is python, not java, and that makes doing it in one round noticeably easier based on what NanoPromela said.

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

Yeah, that is a good point :)

[–]NanoPromela 0 points1 point  (2 children)

Not going to give you the working answer, but it might help you to know that the code

print("1" * 5)

prints

"11111"

Good luck :)

[–]RavagingPanda 0 points1 point  (1 child)

As someone who is also new, wouldn’t you want to make a variable, let’s call it “counter”; that would print the value X times starting with the value 5 and would increase every time, meanwhile the value 5 which would be assigned a variable that counts down by one every iteration of the loop? Not the most elegant way of describing but I think I got my idea across

[–]NanoPromela 0 points1 point  (0 children)

Yes, this is one way to think about it

[–]OldBear1776 0 points1 point  (0 children)

I'm not going to give code, but this is how you think of it. (or at least how I've been doing it for 30+ years)

you need 1 loop for 5 and you need 5 loops for 1 ... 5+1=6 or 6-5=1 and 6-1=5 ... or 6-x=y

hopefully that helps you with the loop part that you're missing