lundi 26 décembre 2016

Python - Nested IF loop

Like many here, I'm new to Python. I'm working on a snippet that asks the user to give their ID, then checks to see if the ID is exactly 6 digits in length. Then the code will ask the user to confirm their ID and if they mistyped, allows them to reset it. If the user confirms their entry was correct, then it asks for a location ID and follows the same path. If both IDs are confirmed, the user then can move on to the rest of the project.

This is something that will have to be input at the start of every use.

The issue I'm running in three sided.

1.) I can enter the empID 101290 and sometimes it tells me it's a valid entry while others it wont (but 101256 works regardless - both are 6 digits)

2.) Entering "1," to confirm the ID, the code moves to block 2 and asks for location ID but if the user enters "2" to say the Employee ID is wrong, it moves on anyway.

Any advice on what's in need of change here?

import time

print('What is your employee ID?') #user assigned ID
empID = input()
while empID != 0:
    print('Try again.')
    empID = input()

# employee ID is only 6 digits in length, no letters
if len(empID) != 6:
    print('Try again.')
elif len(empID) == 6:
    print('Thank you. Your ID is set to ' + empID + '.')
    time.sleep(0.5)
    print('Is this correct?'''
          '[1] Yes  [2] No ')
    yesNo = input()
    while True:
        yesNo == '1'
        print('Thank you. ID set.')
        break
# reset ID
    else:
        print('ID has been reset. Please enter your employee ID.')
        empID = input()
        break
    break

#Store Location ID
print('What is your Location ID?')
locID = input()
while locID != 0:
    print('Try again.')
    locID = input()

# store locations are 3-5 digits
# TODO: prepend any input with less than len 5 with 0
if len(locID) != 5:
    print('Try again.')
elif len(locID) == 5:
    print('Thank you. Your location is set to ' + locID + '.')
    time.sleep(.5)
    print('Is this correct?'''
          '[1] Yes  [2] No ')
    yesNo = input()
    while True:
        yesNo == '1'
        print('Thank you. Location ' + locID + 'set.')
        break
    else:
        print('Location ID has been reset. Please enter your location code.')
        empID = input()
        break
    break
break

next

Aucun commentaire:

Enregistrer un commentaire