0

Can someone explain line 4? I understand the loops, but can quite figure out what line 4 is doing. thanks for any help here.

print("this program draws a horizontal bar graph")
n=input("enter the number of digits. \nn=")
n=int(n)
x=[[" " for j in range(9)] for i in range(n)]
for i in range(n):
 a=input("{} enter each digit:".format(i+1))
 a=int(a)
 for j in range(a):
  x[i][j]="*"
for i in range(n):
 for j in range (9):
  print(x[i][j],"")
  • 1
    It is called list comprehension: https://docs.python.org/3/tutorial/datastructures.html. There is a list comprehension, within list comprehension, in this case. – Nishant Dec 17 '20 at 06:32
  • It is called Python List literal I think, create a list length n, with each element is another list of 9 white space string elements – Phung Duy Phong Dec 17 '20 at 06:33

0 Answers0