I am trying to complete an assignment and I am stuck at the if-else statements area. Could someone please help me? the instructions and what I have so far are below...
Instructions: Your "main" function should do the following: (1) create an empty list; (2) ask the user if he/she wants to perform a list operation. if "yes": (a) prompt the user for the operation: "test", "peek", "add", or "remove"; (b) perform the operation: (i) if "test" then print whether the list is empty or not; (ii) if "peek" then print the number at the beginning of the list (with a label) but don't remove it from the list; (iii) if "add", then prompt the user for a number and add it to the end of the list; (iv) if "remove", then delete the number at the beginning of the list and print it (with a label); (c) print the entire list from beginning to end; repeat step (2) until the user enters "no". What I have so far.. def main(): l = list() x = eval(input('Enter a number: ')) while x >= 0: l.append(x) x = eval(input('Enter a number: ')) ask = input (" Do you want to perform a list operation?") if "yes": input (" Do you want to test, peek, add, or remove?") if "test": if not l: print("The list is not empty") else: print("The list is empty") elif "peek": print(l[0])
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor