0

I have just started learning Python and everything has been going well so far, but I don't really know if I am doing terribly wrong or what's happening. My problem is, I have this code

Y="Y" and "y"
N="N" and "n"
Localname= (getpass.getuser())
print("Welcome User")
time.sleep(1)
print("Identificate")
print ("¿Are you " + Localname + "? (Y/N)")
nameuserauto = input ("> ")
while not nameuserauto == "Y" and "N" and "y" and "n":
    print("INPUT ERROR, PLEASE USE (Y/N)")
    nameuserauto = input("> ")
if nameuserauto == Y:
        nominpu = Localname
        print ("Name saved")
if nameuserauto == N:
        print("Please, write your name")
        nominpu = input("> ")

I just want to make the user have to input the answer again if it is not "Y", "N", "n" or "y". I tried several things, like changing "y" and the caps by variables and that didn't work (I am not sure that would work, though). I am fairly new on this and I couldn't see any similar question. Please help.

Nekuake
  • 1
  • 2
  • `while nameuserauto.strip().upper() != "Y" and nameuserauto.strip().upper() != "N":` or shorter `while nameuserauto.strip().upper() not in ("Y", "N"):`. BTW: You could use `nameuserauto = input("> ").strip().upper()` – furas Dec 11 '16 at 00:29
  • But then, it runs the if I input n or N. I don't know if this is related. – Nekuake Dec 11 '16 at 10:32
  • Your the biggest mistake is `Y="Y" and "y"` it gives result `Y = True` - and you check `nameuserauto == True` - but `"y" == True` gives `True`. You have to use strings in `nameuserauto == "y" or nameuserauto == "Y"` or `nameuserauto in ("y", "Y")` or use `nameuserauto = nameuserauto.upper()` which converts lower `"y"` to upper `"Y"` and you will have to check only `nameuserauto == "Y"` – furas Dec 11 '16 at 10:38

0 Answers0