Error in expected output: Loop is not correctly working
<p>I am still struggling to link the second 'for' variable in this together. The first 'for' loop works correctly, but the second half is stuck on a single variable, which is not allowing it to function correctly in a later repeatable loop. How might I write this better, so that the functions of the text are global, so that the variable 'xcr' isnt local. I know I am a beginner, but any help is always appreciated!! Thanks!</p>

<pre><code>sequence = open('sequence.txt').read().replace('\n','')
enzymes = {}
fh = open('enzymes.txt')
print('Restriction Enzyme Counter')
def servx():
    inez = input('Enter a Restricting Enzyme: ')
    for line in fh.readlines():
        (name, site, junk, junk) = line.split()
        enzymes[name] = site 
        global xcr
        xcr = site
        if inez in line:
            print(xcr)
            print('Active Bases:', xcr)
    for lines in sequence.split():
        if xcr in lines:
            bs = (sequence.count(xcr))
            print(bs)
            print('Enzyme', inez, 'appears', bs, 'times in Sequence.')
</code></pre>

<p>I think you need to specify global inside the <code>servy</code> function and not outside, but even better would be to pass inez as a parameter to <code>servx</code>:</p>

<pre><code>def servy():
    global inez 
    fh.seek(0); #veryyyyy important
    qust = input('Find another Enzyme? [Yes/No]: ')
    qust = qust.lower()
    if qust == 'yes':
        inez = input('Enter a Restricting Enzyme: ')
        servx()
        servy()
    elif qust == 'no':
        print('Thanks!')
    elif qust not in ('yes', 'no'):
        print('Error, Unknown Command')
</code></pre>

<hr>

<p>Or</p>

<pre><code>def servx(inez):
    . . . 



def servy():
    fh.seek(0); #veryyyyy important
    qust = input('Find another Enzyme? [Yes/No]: ')
    quest = qust.lower()
    if qust == 'yes':
        inez = input('Enter a Restricting Enzyme: ')
        servx(inez)
        servy()
    elif qust == 'no':
        print('Thanks!')
    elif qust not in ('yes', 'no'):
        print('Error, Unknown Command')
</code></pre>

python