+ 1

Can anyone explain this Python code by Infant Ray to me in steps.

I want to make my own code that makes Pascal's triangle, but I don't know how to make it so I looked on SoloLearn to get some inspiration. I found this code but I don't understand how it works.(Functions) #function to create a pascal's triangle of size num def pascalGen(num,r=[]): for item in range(num): length = len(r) r = [1 if i == 0 or i == length else r[i-1]+r[i] for i in range(length+1)] yield r #function that draws the triangle def draw_triangle(num): pascal = list(pascalGen(num)) max = len(' '.join(map(str,pascal[-1]))) for p in pascal: print(' '.join(map(str,p)).center(max)+'\n') #enter the size of the triangle draw_triangle(int(input())) #feedback j = (35*'*') k="\nLet me know how you like the code\n" l="\n\t And\n" m="\t Leave\n" n="\t An Upvote\n" o="\t If You Like It ;)" print(j,k,l,m,n,o) Infant Ray created this code.

1st Dec 2018, 4:57 PM
Tibi
Tibi - avatar
3 Respuestas
+ 1
Tibi, you have finished 3/4 of Python tutorial, language-wise you should be able to analyze this yourself. Probably the math of it is not so easy... but that's the challenge after all, isn't it?
1st Dec 2018, 8:52 PM
HonFu
HonFu - avatar
+ 1
Thanks for advice.
1st Dec 2018, 10:25 PM
Tibi
Tibi - avatar
0
I analyzed and commented it in detail here https://code.sololearn.com/c3S89HQvXUrv/#
2nd Dec 2018, 6:36 PM
zemiak