0

I'm new to python and was hoping if someone could help me with this problem.

Here's The code:

uninput1=input('> ')
    while True:
        if 'existing' in uninput1 or 'existing file' in uninput1:
            print ('Please enter the directory of your file.')
            dirfile=input('> ')
            print (space)
            time.sleep(1)
            print ('Now enter the name of your file.')
            nmfile=input('> ')
            print (space)
            time.sleep(1)
            txtmod.existing(dirfile, nmfile)

        elif 'new' in uninput1 or 'create' in uninput1:
            print ('Please enter the directory where you want to create your file.')
            dirfile=input('> ')
            print (space)
            time.sleep(1)
            print ('Now enter the name you want to give to your file.')
            nmfile=input('> ')
            print (space)
            time.sleep(1)
            txtmod.newfile(dirfile, nmfile)


        else:
            print ('Error! Please Try again')

What i'm trying to do is to return an error when the user types a certain thing and restart the loop.But what happens is that instead of restarting the loop it just displays my 'error' forever. Can anyone help?

I don't know if this makes sense or not but i hope it does to someone.

Shell1500
  • 330
  • 1
  • 5
  • 14
  • BTW, `'existing' in uninput1 or 'existing file' in uninput1` can be replaced by `'existing' in uninput1`, since `'existing file' in uninput1` will never be true if `'existing' in uninput1` is false. – PM 2Ring Jul 16 '18 at 15:21
  • [Asking the user for input until they give a valid response](https://stackoverflow.com/q/23294658/953482) may be of interest to you. – Kevin Jul 16 '18 at 15:29

1 Answers1

3

Look at where your input is:

uninput1=input('> ')
while True:
    ...

As you can see, your input is outside the loop - so, when the loop gets repeated, it never gets activated. The solution is simply to move it inside the loop:

while True:
    uninput1=input('> ')
    if ...
    ...
Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53