Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easy answer is: don't print within the <code>while</code> loop, but concatenate up a string to print at the end:</p> <pre><code>result = '' while z &lt; y+1: a = x[z-1] result += str(test[a]) z = z + 1 print result </code></pre> <p>If there are going to be a whole bunch of things, instead of concatenating strings on the fly, use a <code>list</code> and <code>join</code> at the end:</p> <pre><code>result = [] while z &lt; y+1: a = x[z-1] result.append(str(test[a])) z = z + 1 print ''.join(result) </code></pre> <p>But you say you want to get an integer. Do you need that integer, for any reason other than to print it out? If so, you <em>could</em> build up a string and then convert it to an integer:</p> <pre><code>result = [] while z &lt; y+1: a = x[z-1] result.append(str(test[a])) z = z + 1 val = int(''.join(result)) </code></pre> <p>But this is silly. Why not just build up the value as an integer in the first place?</p> <pre><code>val = 0 while z &lt; y+1: a = x[z-1] val = val * 10 + test[a] z = z + 1 </code></pre> <p>Since you seem to be using Python 2, the only way to print without adding a newline, instead adds a space, which doesn't help. But Python 3—and Python 2 with <code>from __future__ import print_function</code>—has a more flexible alternative:</p> <pre><code>while z &lt; y+1: a = x[z-1] print(test[a], end='') z = z + 1 print() </code></pre> <p>Or you can <code>write</code> directly to <code>stdout</code>:</p> <pre><code>while z &lt; y+1: a = x[z-1] sys.stdout.write(str(test[a])) z = z + 1 sys.stdout.write('\n') </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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