0

Firstly, let me write down my code for you.

def AorB():

    with open('AB.txt', 'r+') as f:
        A = ['A', 'The Letter A']
        B = ['B', 'The Letter B']
        c = input('Write A or B >>>_ ')
        if c in A:
            print('You wrote A')
            add = input('Write Something Here! >>>_ ')
            f_contents = f.read()
            f.seek(0)
            f.write(add + '\n')
            more_line = input('Would you like to write more lines? >>>_ ')
            if more_line == 'Y' or 'y':
                AorB()
            if more_line == 'N' or 'n':
                print('You wrote No!')
AorB()

What the result is...

Write A or B >>>_ (Wrote A)
You wrote A
Write Something Here! >>>_ (Writes Something.)
Would you like to write more lines? >>>_ (Wrote N)
Write A or B >>>_ 

As you can see it looped back to the beginning. my desired result is

Write A or B >>>_ (Wrote A)
You wrote A
Write Something Here! >>>_ (Prints something.)
Would you like to write more lines? >>>_ (N)
You wrote No!
drkostas
  • 517
  • 1
  • 7
  • 29
EVO
  • 29
  • 3

1 Answers1

0

Close, you just need to change the syntax a bit. Try this

if more_line == 'N' or more_line == 'n':

and you'll want to change this one too

if more_line == 'Y' or more_line =='y':

Explanation:

Python is translating if more_line == 'Y' or 'y': into this if more_line == 'Y' or if 'y' then do some stuff. The second part (if 'y') is always true so the rest doesn't get evaluated.

SuperStew
  • 2,857
  • 2
  • 15
  • 27