0

I'm new to python, So I was trying to make a login application. In this application, the main menu consists of 1) Creating acc, if you don't have one. 2) Login, to login with your previously created acc at 1). This is the code :

def main():
    menu()

def menu():
    menuOption = print("Choose your option"
                    "1) Create Acc"
                    "2) Login")
    
    if menuOption == 1:
        createAcc()
    else:
        login()  
    
def createAcc():
    input1 = input("Choose username : ")
    input2 = input("Choose password : ")
    return input1, input2

def login(input1 , input2):
    print("Enter login details")
    
    input3 = input("Enter username : ")
    input4 = input("Enter password : ")

    if input3 == input1 and input4 == input2:
        print("Access granted")
    else:
        print("Access denied")

    input1, input2 = createAcc()
    login(input1, input2)

def information():
    print("Enter your details")

    name = input("Name : ")
    age = input("Age : ")
    pNum = input("Phone Number : ")
    address = input("Address : ")
    hpnum = input("Home telephone number : ")

def family():
    print("Enter your family details ")

    father = input("Father name : ")
    mother = input("Mother name : ")

    siblingCNT = input("How many siblings do you have?")
    for i in range(siblingCNT):
        sibName = input("Enter name : ")

main()

The problem is I got an error on line 12 at Login() def. This is the error :

TypeError: login() missing 2 required positional arguments: 'input1' and 'input2'

How to solve this and anything I can do to making my application better? Thanks in advance for any suggestions.

Btw I'm using vscode with the latest version and python 3.8.5 64-bit.

rioV8
  • 24,506
  • 3
  • 32
  • 49
ezaryf
  • 11
  • 3
  • 1
    You're calling `login()`, but you defined login to have two parameters: `def login(input1 , input2):`, so where are the function arguments? – Grismar Oct 12 '20 at 02:03
  • Does this answer your question? [Python function global variables?](https://stackoverflow.com/questions/10588317/python-function-global-variables) – Osman Durdag Oct 12 '20 at 02:08
  • User need to input their own username and password in input1 and input2. – ezaryf Oct 12 '20 at 02:17
  • 1
    even when you login correct you are asked to create a new account – rioV8 Oct 12 '20 at 09:58

1 Answers1

0

The values stored in input1 and input2 only exist in your createAcc() function.

I suggest you define these as global variables and change login(input1,input2) to just login()

Weirdo
  • 42
  • 9
  • If I did this, the user needs to enter input into input1 and input2 every time the code run? But I just want the user only needs to input when they choose createAcc? Or could you please do me a favor by providing an example of code by your suggestion then I would be more clear on that. – ezaryf Oct 12 '20 at 02:20
  • If this is just for learning, I guess you could store input1 and input2 in a txt file and retrieve them/compare with input3 and input4. – Weirdo Oct 12 '20 at 02:25