-4
user1 = "aqa code" 
pass1 = "uzair123"
username = input("Enter username: ")
password = input("Enter password: ")
while username !=  user1:
    print("Access denied: username is incorrect try again ")
    username = input("Enter username again: ")
    if username == user1:
        print("access granted")
        while password != pass1:
            print("Password is still incorrect")
            password=input("Enter password again: ")
            if password == pass1:
                print("Access granted")
while password != pass1:
    print("Access denied,Password is incorrect")
    password=input("Enter password again: ")
    if password == pass1:
        print("Access granted")

How do I add a .lower() to the username/user1 so it becomes case insensitive when you type in the answer? Please help.

  • 1
    You can simply use `username.lower() == user1` instead of `username == user1` – ettanany Nov 14 '16 at 21:31
  • Possible duplicate of [How to convert string to lowercase in Python?](http://stackoverflow.com/questions/6797984/how-to-convert-string-to-lowercase-in-python) – Nikaido Nov 14 '16 at 21:45

2 Answers2

0

You can call .lower on the return of the input function.

username = input("Enter username: ").lower()
password = input("Enter password: ").lower()
James
  • 32,991
  • 4
  • 47
  • 70
0

Adding .lower() is indeed the solution you're looking for, but you may want to try to simplify your flow a bit, so you have fewer places to edit whenever you want to modify your input statement. To do this I would suggest creating a variable for each loop that is initially false and only get user input once inside each loop:

loop_condition = False  #initialize loop condition
while not loop_condition:  #loop until we say so
    value = input("please enter a value: ")  #human input
    value = value.lower() #convert to lower case for comparison
    if value == "password":  #test
        print("success")
        loop_condition = True  #loop will terminate when we hit our `while` again
    else:
        print("fail")
print("rest of program goes here")

Here you can see we only call input() once, and only have to convert it to lowercase in one place as well. Simplicity is always your friend.

note: use raw_input() if you're using python 2.7

Aaron
  • 10,133
  • 1
  • 24
  • 40