Simple Todo Application

Source Code:

#***************ProgrammerFect******************#

from sys import exit
#GLOBAL DS
users = {}
counter = 0
def adduser():
    """
        THIS FUNCTION WILL ADD A USER
    """
    global users
    username = input('ENTER USER NAME : ')
    password = input('ENTER PASSWORD : ')
    users.setdefault(username.lower(),[password])
    print('USER SUCCESSFULLY ADDED!')
    mainmenu()

def addtask(username,func):
    global users
    if username:
        while True:
            task_description = input('ENTER TASK DETAILS : ')
            task_status = "Pending"
            users.get(username)[-1].append([
                task_description,
                task_status
            ])
            ch = input('ADD MORE TASKS ? : ')
            if ch[0].lower() == 'n':
                break;
        func(username,func)
def showtasks(username,func,flag = False,):
    global users
    i = 0
    for x in users.get(username)[1:]:
        print(f"{i+1} --> {x}")
    if flag:
        func(username,func)
def changestatus(username,func):
    if username:
        showtasks(username,func)
        id = int(input('ENTER TASK ID : '))
        tasks = users.get(username)[1:]
        print(tasks[id-1][0],end = " : ")
        status = input()
        tasks[id-1][-1] = status
        paswd = users.get(username)[0]
        tasks.insert(0,paswd)
        users[username]=tasks
        print("STATUS HAS BEEN CHANGED")
        func(username,func)

def deletetask(username):
    pass

menu = {
    1:("ADD TASK",addtask),
    2:("CHANGE STATUS",changestatus),
    3:("DELETE TASK",deletetask),
    4:("SHOW TASKS",showtasks)
}   
def taskmenu(username,func = None):
    global menu
    print('-'*50)
    for k,v in menu.items():
        print(f"{k} --> {v[0]}")
    print('-'*50)
    ch = int(input('OPTION : '))
    if ch in menu.keys():
        if ch == 4:
            menu.get(ch)[-1](username,taskmenu,flag=True)
        else:
            menu.get(ch)[-1](username,taskmenu)
    else:
        print('WRONG CHOICE TRY AGAIN!')
        taskmenu(username)
def login():
    global users
    global counter
       
    username = input('ENTER YOUR USER NAME : ')
    if username.lower() in users.keys():
        counter = 0
        password = input("ENTER YOUR PASSWORD : ")
        #print(users.get(username))
        if password == users.get(username)[0]:
            if len(users.get(username)) == 1:
                users.get(username).append([])
            taskmenu(username)
        else:
            counter += 1
            print('WRONG PASSWORD PLEASE TRY AGAIN')
            if counter <=3:
                login()
    else:
        counter =+1
        print('INVALID  USER NAME PLEASE TRY AGAIN')
        if counter <= 3:
            login()
           
main_menu = {
    1:("LOGIN",login),
    2:("ADD NEW USER ",adduser),
    3:("EXIT",exit)
}
def mainmenu():
    global main_menu
    print('-'*50)
    for k,v in main_menu.items():
        print(f"{k} --> {v[0]}")
    print('-'*50)
    ch = int(input('OPTION : '))
    if ch in main_menu.keys():
        main_menu.get(ch)[-1]()
    else:
        print('WRONG CHOICE TRY AGAIN!')
        mainmenu()
       
mainmenu()

Output:

 


 

Comments