Note that there are some explanatory texts on larger screens.

plurals
  1. POfunction to write initials using x's
    primarykey
    data
    text
    <p>I have been tasked to write a function that will print within itself my initials. if you have no initials it prints x in the middle, I don't have a middle initial. He told us to go ahead and hard code the list we were going to input into the function.</p> <p>So my function grabs a list with the column number where x should be printed. It goes through the numbers in the list, checks if it equals the index number and if it does it prints a x, if it doesn't not it prints white space, then it decreases the index value by 1, and repeats the process until all numbers in the list have been checked. I'm supposed to do all so that the function goes through each line (1st list) of the 2nd list but I cant get it to do that so I just replicated the 2nd list in 1st and ran the function with all the 1st list. this is my code</p> <pre><code>import sys # function thst takes each row of the namelist and determines where to print x def oned (row) : index = 11 while index &gt;= 0 : for numbers in row : if numbers == index : sys.stdout.write('X') else : sys.stdout.write(' ') index = index - 1 print #Main namelist = [[11, 2, 1, 0], [11, 2], [11, 2], [11, 8, 5, 2, 1, 0], [11, 7, 6, 0], [11, 7, 6, 0], [11, 8, 5, 2, 1, 0]] testrow0 = [11, 2, 1, 0] testrow1 = [11, 2] testrow2 = [11, 2] testrow3 = [11, 8, 5, 2, 1, 0] #only prints 11, 2, 1, 0 needs 8, 5 testrow4 = [11, 7, 6, 0] #only prints 11, 0 needs 7,6 testrow5 = [11, 7, 6, 0] #skips over 7, 6 like other one testrow6 = [11, 8, 5, 2, 1, 0] #skips over 8, 5 oned (testrow0) oned (testrow1) oned (testrow2) oned (testrow3) oned (testrow4) oned (testrow5) oned (testrow6) </code></pre> <p>out put is </p> <pre><code>X XXX X X X X X XXX X X X X X XXX </code></pre> <p>Which is what I want but the x in between is missing. I can't seem to find the error that is causing this so if you can find it please let me know.</p> <p>I want the output to look like:</p> <pre><code>X XXX X X X X X X X XXX X XX X X XX X X X X XXX </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload