[Solved] Python, using nested lists (list of lists) from user input [closed]


So if I’m understanding correctly, the “Lists of List” comment pertains to nested Lists, The code you have is close to what’s needed.
I believe this is what you need.

print("Enter First name, last name and Student ID number. Then press 0 to continue")

userFirst = str(input("Enter First Here:"))
userLast = str(input("Enter Last Name:"))
userStudent = int(input("Enter Student ID number:"))
userInfo = input("Enter more details or pres 0 to enter search mode")

while userInfo != "0":
    userInfo=input("Enter more details")
else:
        print("Search Mode")

###Changed SearchMode to be nested list with each list Holding the input values from [ [UserFirst],[userLast],[userStuden] ]
searchMode = [[],[],[]]
    ### Append userFirst to the first Indexed List
searchMode[0].append(userFirst)
    ### Append userLast to the second Indexed List
searchMode[1].append(userLast)
    ### Append userStudent to the third Indexed List
searchMode[2].append(userStudent)

userSearch = int(input("Enter Student ID"))

### Since we know that we need to search by The Student Id we Take the InitialList and add the index of our desired Nested List; In this Case it's the 3rd nested
### Then we take the values from the nested List and look for the inputted value and obtain the record corresponding index
userSearch = searchMode[2][userStudent-1]
print(userSearch)

Let me know if this doesn’t give you the results you need and I’ll try working on it some more

update:
For the fun of it, I recreated the process to be called as a function.

def SearchRequest():
    ### This Will Hold our Input Data
    SearchData = [[],[],[],[]]

    ### This Will Run The Question Prompts We Want Filled
    def promptQuestions():

        # Get User First Name
        def userFirst():
            return SearchData[0].append(str(input('Enter First Name Here: ')))

        # Get User Last Name
        def userLast():
            return SearchData[1].append(str(input('Enter Last Name Here: ')))
        # Get User Student ID
        def userStudent():
            return SearchData[2].append(int(input('Enter Student ID Number: ')))

        # Ask If They Want to Add Additional Info; Entering 0 Will Exit The Asking Phase
        # Once Completed We Will Start the UserId Lookup Phase
        def userInfo():
            #Beginning Prompt
            userInfo = input('Enter More Details Or Press 0 to Enter Search Mode')
            #List We'll Be Using To Hold Inputs
            output = []
            #Append First input To our Output List
            output.append(userInfo)

            while userInfo != "0":
                #If 0 Was Not Entered: Ask To Enter More Details
                userInfo=input('Enter More Details: ')
                #Append Details To Our Output List
                output.append(userInfo)
            else:
                print('Entering Search Mode')
                #Append Result List To Our Main Search Data
                SearchData[3].append(output)

        # Ending Of Prompt Questions
        def runQuestions():
            """This will be used to hold the order of execution"""
            userFirst()
            userLast()
            userStudent()
            userInfo()
            return SearchData
        return runQuestions()

        #Create a Search Mode Allowing User To Lookup ID
    def SearchMode():
            #Gets Input ID to LookUP
        def SearchStudentID():
            return int(input('Enter Student ID: '))
        #Returns the matching ID as long as the ID is the same as the index Number
        return SearchData[2][SearchStudentID()-1]


    # Final Layer to Our Searching Process
    def runSearchProcess():

        #Begins Main Prompt Phase
        promptQuestions()

        #Once Everything is completed, Return the search Modes Result
        return SearchMode()
    #Ending Of Search Request
    return runSearchProcess()


print(SearchRequest())

3

solved Python, using nested lists (list of lists) from user input [closed]