0

Quick question for loop print pattern Python!

##This is my code### print('Print the Pattern') z = input('Enter a whole number: ') n = int(z) s = input('Enter a symbol: ') for i in range(n): for j in range(i+1): print(s,end='') print() ############################### the output is a descending right triangle # ## ### #### ##### I need to figure out how to switch the code so that it outputs only the outline like this # # # # # # # # # help is appreciated!:D

14th Feb 2021, 2:09 AM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
2 Answers
+ 10
where's the attempt?
14th Feb 2021, 2:41 AM
Ded
+ 4
Gutz_X_73vEn Just replace the middle part with whitespaces instead of the symbol. 1. Print first the symbol without the trailing new line 2. Then print the whitespaces only inside the second for loop. 3. Last, after the iteration of for loop, print again the symbol. [ Additional ] I remove the input prompt/text temporarily for now as it won't output in code playground properly and will affect the drawing. Anyway, here is the first solution from your code: https://code.sololearn.com/cSy5wFkF4JD7/?ref=app Here is an another solution which is shorter and just the same with the first one. https://code.sololearn.com/czCUceng1T87/?ref=app If you need additional explanation regarding this, just please feel free to ask. Thanks! .
14th Feb 2021, 5:35 AM
noteve
noteve - avatar