0

Sorry if I seem stupid but I need help to understand this code.

https://code.sololearn.com/cAc9530koqqK/?ref=app

15th Jan 2020, 1:56 PM
Yusof
Yusof - avatar
7 Respostas
+ 1
With end = "" in print you dont make a new line when calling print. Surrounded by a for loop "*" is printed 5 times in one line. After the inner for loop you call print () which prints a new line by default so in the 5 iterations of the outer for loop you print 5 lines with each 5 times "*" And dont call yourself stupid. Everyone has to start at some point ;)
15th Jan 2020, 2:17 PM
Jnn
Jnn - avatar
+ 1
Thank you Danigamy
15th Jan 2020, 2:23 PM
Yusof
Yusof - avatar
0
What exactly do you not understand?
15th Jan 2020, 1:59 PM
HonFu
HonFu - avatar
0
Let's first look at the inner for loop: for i in range(5): print("*", end="") What does it do? It prints "*" for 5 times, each time without moving to a new line. So you get output as: ***** Now let's look with the outer loop: for i in range(5): for i in range(5): print("*",end="") print() It repeats what the inner loop does, for 5 times (plus it adds a new line with print()). And hence "*****" with new line 5 times gives: ***** ***** ***** ***** *****
15th Jan 2020, 2:09 PM
Danigamy
Danigamy - avatar
0
Yusof Hany You are welcome!
15th Jan 2020, 2:24 PM
Danigamy
Danigamy - avatar
0
thank youJnn
15th Jan 2020, 2:45 PM
Yusof
Yusof - avatar
0
you could have just run the code its kinda self explanatory you should learn the basics or at least play with the code and see what it does
17th Jan 2020, 11:02 AM
userx
userx - avatar