Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Simple list manager
  • Alright this is a very simple program I wrote. I'm putting it here for examples on how to handle lists in Python.


    #!/usr/bin/python
    #Simple list manager by chroniccommand
    import sys

    list = []

    def listman():
    print(\"1 - Add to list\n2 - Delete from list\n3 - List length\n4 - Exit\")
    choice = raw_input(\"Choice: \")
    if choice == \"1\":
    lstadd()
    elif choice == \"2\":
    lstrm()
    elif choice == \"3\":
    lstlen()
    elif choice == \"4\":
    sys.exit()
    elif choice == \"\":
    print(\"Please select an option!\")
    listman()
    def lstadd():
    input = raw_input('What do you want in the list: ')
    list.append(input)
    print list
    listman()

    def lstrm():
    choicerm = raw_input(\"What do you want to remove? \")
    try:
    list.remove(choicerm)
    print list
    listman()
    except:
    print(\"Could not remove. Maybe it doesnt exist in the list?\")
    print list
    listman()

    def lstlen():
    print(len(list)) #Prints the length of list.
    print list
    listman()

    def main():
    print(\"1 - List manipulation\n2 - Exit\")
    inputmain = raw_input(\"Choice: \") #Main menu raw input
    if inputmain == \"1\":
    listman()
    elif inputmain == \"2\":
    sys.exit()

    main()