Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Putting an array for each string that is printed to a loop ClaudioSimonetti Unladen Swallow Posts: 1 Threads: 1 Joined: Feb 2019 Reputation: 0 Likes received: 0 #1 Feb-05-2019, 09:50 AM I would like to be able to push each | into an array Here is my function: ```def pyramide(lines): k = 1 * lines - 1 for i in range(0, lines): for j in range(0, k): print(end=" ") k = k - 1 for j in range(0, i+1): print("|", end=" ") print("\r") lines = 5 pyramide(lines)```What I tried: ```for j in range(0, i+1): each = print("|", end=" ") array.push(each) print("\r")```But it doesn't seem to add it into an array, my question is how I can push each | into an array so I can delete it later expected input: `pyramide(5)`expected output: ``` | | | | | | | | | |```Then I should be able to remove a | from each line by ``` stickDelete(3, 2) # first paramater is the line, second is how much | would like to delete | | | | | | |```Thanks for reading. perfringo Da Bishop Posts: 1,139 Threads: 5 Joined: Jun 2018 Reputation: 117 Likes received: 256 #2 Feb-05-2019, 12:52 PM (This post was last modified: Feb-05-2019, 01:03 PM by perfringo. Edited 1 time in total.) Do you want 'push each '|' into array' or want expected output? You can approach this from different angle and without any complicated indices handling: ```def pyramide(lines): for line in range(lines+1): print(f'{" |" * line:^{lines * 2}s}') pyramide(5) | | | | | | | | | | | | | | | ```You should keep in mind that all functions what don't return or yield anything from body will return None. If you want to be able skip some symbols in rows then you can simply: ```def pyramide(lines, row, qty): for line in range(lines+1): if line == row: print(f'{" |" * (line - qty):^{lines * 2}s}') else: print(f'{" |" * line:^{lines * 2}s}') pyramide(7, 5, 2) | | | | | | | | | | | | | | | | | | | | | | | | | | ```Both functions print empty line at first line, to get rid of that use range(1, lines+1) I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Putting frames on separate lines kenwatts275 2 141 Dec-09-2019, 09:53 PM Last Post: kenwatts275 I get "None" at the end of my printed result. dyshkant 3 179 Sep-06-2019, 06:31 PM Last Post: dyshkant bytes not being printed as expected Skaperen 2 194 Aug-27-2019, 05:33 AM Last Post: Skaperen reading txt file putting in list function Expel 7 365 Jul-17-2019, 03:18 PM Last Post: Expel Change linenumber and filename printed in exceptions like #line in C kryptomatrix 2 283 Jul-12-2019, 06:01 AM Last Post: Gribouillis converting array to and from string in python 3.7.2 srm 5 538 Jul-03-2019, 01:11 PM Last Post: snippsat Loop through array items dynamically in a certain format bhojendra 3 264 Jun-11-2019, 03:37 AM Last Post: micseydel python3 List to array or string to extract data batchenr 4 489 May-28-2019, 01:44 PM Last Post: buran change array column values without loop khalidreemy 2 278 May-05-2019, 09:05 AM Last Post: DeaD_EyE Putting text on images from excel/csv file sam77am 1 350 Apr-05-2019, 07:36 AM Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)