Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.4 kB
3
Indexable
Never
user_info = dict()
def add_person():
    prompt = "Enter name,phone number, and country: "
    info = list(map(str, input(prompt).split()))
    user_info[len(user_info.keys())] = info
def search_person(name):
    for x in user_info.items():
        if name == x[1][0]:
            return f"Key = {x[0]}"
        else:
            return "Not found"
def del_person(name):
    del user_info[search_person(name)] #have to watch out for error via keyerror, etc. Debug in case name doesn't exist in dict.

def modify_person(name):
    num = int(input("Enter position of data to modify: "))
    data = input("Enter new data: ")
    user_info[search_person(name)][num] = data
def display_all():
    for x in user_info:
        print(f"Student {x+1}:")
        for y in range(3):
            print(user_info[x][y],end = ' ')
     
while True:
    prompt = "Enter a to add, s to search, d to delete, m to modify, or di to display all. To quit enter q: "
    val = input(prompt)
    if val in ['s','d','m']:
        namee = input("Enter name: ")
    if val == 'q':
        #quit system
        break #sys.exit() after importing would work as well
    elif val == 'a':
        add_person()
    elif val == 's':
        print(search_person(namee))
    elif val == 'd':
        del_person(namee)
    elif val == 'm':
        modify_person(namee)
    elif val == 'di':
        display_all()

print(user_info)