Python Forum
Beginner: I need help understanding few lines of a code.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner: I need help understanding few lines of a code.
#1
num=int(input('Enter the looping number: '))
for i in range(num):
    for j in range(i):
        print(i, end=' ')
    print(" ")
I wrote a program myself to get a pattern of user prompted number. It worked as I hoped. But I came across above given code. I need help in understanding both the print part and how it works to give following output.

Enter the looping number: 5

1
2 2
3 3 3
4 4 4 4
Reply


Messages In This Thread
Beginner: I need help understanding few lines of a code. - by hop_090 - Sep-07-2020, 03:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code understanding: Need help in understanding dictionary code jt123 0 536 Jul-09-2023, 01:13 PM
Last Post: jt123
  Beginner: Code not work when longer list raiviscoding 2 951 May-19-2023, 11:19 AM
Last Post: deanhystad
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 2,028 May-09-2023, 08:47 AM
Last Post: buran
  Regular Expression search to comment lines of code Gman2233 5 1,817 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  Understanding a piece of code Michael1 4 1,548 Jan-20-2022, 07:14 PM
Last Post: Michael1
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,346 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
  python seems to be skipping lines of code alansandbucket 1 4,333 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  Running a few lines of code as soon as my timer ends nethatar 3 2,533 Feb-26-2021, 01:02 PM
Last Post: jefsummers
  Assistance with running a few lines of code at an EXACT time nethatar 5 3,458 Feb-24-2021, 10:43 PM
Last Post: nilamo
  Making new lines of code AvioxyYT 1 1,880 Jan-22-2021, 07:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020