Christie
Christie

Reputation: 113

Problem getting user input from the console

I am probably overlooking something very simple here but for some reason when i run this block of code, it will only ask for the menu_selection var, it will not ask for input from any of the if cases

import user

print("1.) Login")
print("2.) Register")
print("3.) Exit")

menu_selection = input("Selection:")

if menu_selection == 1:
    username = input("Enter username:")
    password = input("Enter password:")
    login_user = username, password

elif menu_selection == 2:
    username = input("Enter username:")
    password = input("Enter password:")
    new_user = user.User(username, password)

elif menu_selection == 3:
    exit("PyMess closed.")

Upvotes: 1

Views: 48

Answers (1)

modesitt
modesitt

Reputation: 7210

Because the result stored in menu_selection will be a string - as that is the return type of input. Make it an int.

menu_selection = int(input("Selection:"))

Note that this will fail if you enter a non-integer value when you run the program.

Upvotes: 2

Related Questions