Q:

While Loop Response & Look File

I have been at a two day loss trying to figure something out (probably due to my limited ability coding) Usgin Python 3.4.1
I am trying to design a series of options for an input and have option "4" be the pass but only if a file is present in specific location. I can press any number anytime and it repeats. However if I select 4 and the file is not present it comes back with Incorrect but no matter the next answer it continues my program.
print ("Please Choose From the Following Options")
print ("1. Option A")
print ("2. Option B")
print ("3. Option C")
print ("4. Option D")
print ("5. Option R")
monkeyGuess = input("Selection: ")

monkey = "4"

while monkey != monkeyGuess:
    print ()
    print ("Incorrect")
    monkeyGuess = input("Selection: ")

while monkey == monkeyGuess:
    try:
        with open('c:\test.txt') as file:
            break
            pass
    except IOError as e:
        time.sleep(1)
    print ()
    print ("Incorrect")
    monkeyGuess = input("Selection: ")

I tired combing the two and with little results:
while monkey != monkeyGuess:
    time.sleep(1)
    print ()
    print ("Incorrect Inputs Found")
    monkeyGuess = input("Selection: ")
    monkey == monkeyGuess or os.path.isfile('test.txt') 
    print ()
    print ("Incorrect Inputs Found")
    monkeyGuess = input("Selection: ")

A:

Your first approach doesn't work because once the correct input (4) has been entered, the first while loop has been passed, and all the user has to do to bypass the second loop is to pick a wrong input, because then while monkey == monkeyGuess will be False and the loop will stop.
The second approach is missing an if statement, but even if it had one, all the user needs to do is to make while monkey != monkeyGuess: False by picking the correct number - whether or not the file exists doesn't matter.

Solution:
print ("Please Choose From the Following Options")
print ("1. Option A")
print ("2. Option B")
print ("3. Option C")
print ("4. Option D")
print ("5. Option R")

monkey = "4"

while True:
    monkeyGuess = input("Selection: ")

    if monkeyGuess != monkey:
        print ()
        print ("Incorrect")
        continue

    try:
        with open('c:\test.txt') as file:
            break
    except IOError as e:
        print ()
        print ("Incorrect")

Generally, a while True loop is best suited for this scenario. Ask for user input inside the loop, and then break out of the loop using if statements.

