+ 1

How it results the square like figure? I can't get that..

for i in range(10): print (i*"*"+(10-i)*"*")

15th May 2020, 6:26 PM
Bhanu Tripathi
Bhanu Tripathi - avatar
2 Respuestas
+ 3
it's like this: 0 * "*" + (10-0) * "*" meaning 0 stars at beginning + 10 stars at end 1 * "*" + (10-1) * "*" meaning 1 star at beginning + 9 stars at end 2 * "*" + (10-2) * "*" meaning 2 stars at beginning + 8 stars at end 3 * "*" + (10-3) * "*" meaning 3 stars at beginning + 7 stars at end 4 * "*" + (10-4) * "*" meaning 4 stars at beginning + 6 stars at end 5 * "*" + (10-5) * "*" meaning 5 stars at beginning + 5 stars at end 6 * "*" + (10-6) * "*" meaning 6 stars at beginning + 4 stars at end 7 * "*" + (10-7) * "*" meaning 7 stars at beginning + 3 stars at end 8 * "*" + (10-8) * "*" meaning 8 stars at beginning + 2 stars at end 9 * "*" + (10-9) * "*" meaning 9 stars at beginning + 1 star at end 10 * "*" + (10-10) * "*" meaning 10 stars at beginning + 0 stars at end
15th May 2020, 7:51 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 2
for i in range(10): print(10 * "*") Is more simpler anyways, n * aString returns the string repeated n times like 2 * "foo" is "foofoo".
15th May 2020, 7:48 PM
Mahmud Nabil
Mahmud Nabil - avatar