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.

2
  • 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. Commented Jul 16, 2018 at 15:21
  • Asking the user for input until they give a valid response may be of interest to you. Commented Jul 16, 2018 at 15:29

1 Answer 1

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 ...
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.