0

I have to create a list with a menu options for
1. Add,
2. Remove,
3. Check if element exists,
4.Display list,
5. would you like to Continue?
6. Exit
I could write the code so far. Pls help me complete it. (ASAP)

fruits = ['Apple', 'Banana', 'Grapes', 'Peach']
#while 1:

ch = int(raw_input('1. Append \n2. Remove \n3. Exists \n4. Display \n5. Exit \nEnter Your Choice'))

if (ch == 1):
    f_app = raw_input('Enter the fruit to be added')
    fruits.append(f_app)
    print fruits

elif (ch == 2):
    print fruits
    f_rem = raw_input('Enter the fruit to be removed')
    fruits.remove(f_rem)
    print fruits

elif (ch == 3):
    f_exists = raw_input('Enter the fruit to be checked')
    if f_exists in fruits:
        f_in = fruits.index(f_exists)
        print '"%s" exists in the list at index "%s"' %f_exists%f_in
    else:
        print '"%s" does not exist' %f_exists

elif (ch == 4):
    print fruits

elif (ch == 5):
    print ('Exiting!!!')

else:
    print 'Invalid Choice'
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by sravanthi89
0

Only strange thing I see is print line in exist case, which has twice % instead of tuple:

print( '"%s" exists in the list at index "%s"' % (f_exists, f_in))

Just enable the while loop, fix exit, fix little output format and you are done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.