Click here to Skip to main content
14,243,950 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have an insert function which returns a tuple. The tuple contains name,tribename,ID,air,water,earth,fire.

So i'm trying to use my delete avatar function to access the tuple's ID variable to match with the user's input.

However,I'm facing issue I believe is the way i'm trying to access is wrong or there is a more straight forward way to do this comparison to delete it. Hope I can get some help!

What I have tried:

#this is what my insert function looks like
def insert_avatar(): 
    print("Insert a new avatar")
    name_loop = True
    number_loop = True
    tribe_loop = True
    while name_loop :
        name = input("Enter Name:")
        if name >= "a" and name <= "z" or name >= "A" and name <= "Z":
            name_loop = False
    while number_loop:   
        three_integer = str(input("Enter id three integers:"))
        if len(three_integer)==3:
            number_loop = False
            print("Please enter 3 digits")
    while tribe_loop:
        tribename = input("Enter tribe:")
        if tribename >= "a" and tribename <= "z" or tribename >= "A" and tribename <= "Z":
            tribe_loop = False 
            print("Please enter letters only")
    air = int(input("Air:"))
    water = int(input("Water:"))
    earth = int(input("Earth:"))
    fire = int(input("Fire:"))
    id_F_letter = tribename[0].upper()
    average_power = (air + water + earth + fire)/4
    if average_power >=80:
            last_letter = 'A'
    elif average_power >= 70:
        last_letter ='B'
    elif average_power >= 60:
        last_letter ='C'
    elif average_power >=50:
        last_letter ='D'
    elif average_power >= 40:
        last_letter ='E'
        last_letter = 'F'
    ID = id_F_letter + str(three_integer)+ last_letter
    print("New Avatar with ID {0} Inserted\n".format(ID))
    list_item = name,tribename,ID,air,water,earth,fire           
    return list_item

#delete function
def d_avatar(list_item):
    print("Delete an avatar")
    deletion = input("Enter avatar id to delete: ")
    mylist = list(list_item)    
    for value in enumerate(mylist):
        if value == deletion:
            del mylist[3]
            print("avatar ID is not found")
            deletion = input("Enter avatar id to delete: ")

# this is the menu choice 
while True:
        choice = menu()
        if choice == "1":
            mylist = insert_avatar()
            identity = []    
            for i in range(1):             
        elif choice == "2":
Updated 24-May-19 21:53pm
Richard MacCutchan 24-May-19 12:51pm
You need to show the code where the list_item variable is returned, before the choice statements.
darryl wong 24-May-19 13:35pm
okay made an update thanks!:)
Richard MacCutchan 25-May-19 3:31am
You have not shown the code where list_item is set before calling the delete method.
darryl wong 25-May-19 3:48am
its at the end of my insert function is where i assigned the tuple to a variable called list_item before returning. Is not that or am i missing something?
darryl wong 25-May-19 3:54am
maybe i really missed out something i have re-editted so sorry
Richard MacCutchan 25-May-19 4:07am
Yes, you have missed reading your code. The return value from insert_avatar you have named mylist, not list_item.
darryl wong 25-May-19 6:47am
list_item = name,tribename,ID,air,water,earth,fire
return list_item
This is my return value in my insert_avatar though it's wrong?
Richard MacCutchan 25-May-19 10:01am
Look at your code:
            mylist = insert_avatar()

You have called it mylist!
darryl wong 25-May-19 10:07am
oh right so sorry i was confused what you were referring to will try make a change. thank you! it works.
However for some reason it doesn't delete the ID i just entered.
It just goes into this:
print("avatar ID is not found")
deletion = input("Enter avatar id to delete: ")

appreciate the help!
Richard MacCutchan 25-May-19 10:26am
Add some print statements to your code so you can see the values of all the items you are processing. It is no use trying to guess why it does not find the id number in the list.
darryl wong 25-May-19 22:23pm
okay yup got it thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100