Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Range returns either a list of int, or an iterable of int, depending on which version of Python you are using. Attempting to assign that single int into two names causes Python to attempt to iterate through that int in automated tuple unpacking.</p> <p>So, change the </p> <p><code>for index, y in range(index + 1, y):</code></p> <p>to</p> <p><code>for y in range(index + 1, y):</code></p> <p>Also, you use <code>index + 1</code> repeatedly, but mostly to look up the next symbol in your cformula. Since that doesn't change over the course of your outer loop, just assign it its own name once, and keep using that name:</p> <pre><code>for index, x in enumerate(cformula): next_index = index + 1 next_symbol = cformula[next_index] if x == 'C': if next_symbol == 'H' or next_symbol == 'O': C1 += 1 else: for y in range(next_index, 1000000000): if next_symbol != 'H' or next_symbol != 'O': num = y*10 + int(next_symbol) else: C1 += num break </code></pre> <p>I've also refactored out some constants to make the code cleaner. Your inner loop as written was failing on tuple assignment, and would only be counting up the <code>y</code>. Also, your index would be reset again once you exited the inner loop, so you would be processing all of your digits repeatedly.</p> <p>If you want to iterate over the substring after your current symbol, you could just use slice notation to get all of those characters: <code>for subsequent in cformula[next_index:]</code></p> <p>For example:</p> <pre><code>&gt;&gt;&gt; chemical = 'CH3OOCH3' &gt;&gt;&gt; chemical[2:] '3OOCH3' &gt;&gt;&gt; for x in chemical[2:]: ... print x ... 3 O O C H 3 </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. 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