I am trying to have a user select from amongst a list of items, and then make use of that choice later on as both a string (e.g. "you chose _____"). My function currently allows for a numerical choice, but I am not sure how to return it as the item (e.g. apple) rather than the integer corresponding to the position in the list:

def get_material(mylist):
        mycount = 1
        for item in mylist:
                print mycount, item
                mycount = mycount + 1
        material = raw_input("Please select material:")
        myposition = int(material) - 1
        return myposition

fruit_list = ['apple', 'orange', 'banana']

fruit = get_material(fruit_list)

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to