Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Array function testing, add, remove, insert values
- #Steve Basford 2015
- from array import *
- array1 = array('i', [1,2,3,4,5,6,7,8,9,10]) #defines the array
- while True:
- user = input("What would you like to do? \n(P)rint (A)dd (D)elete (I)nsert or (Q)uit?") #displays menu of choices
- if user == "q": #if user wants to exit
- print("Goodbye")
- break #breakl the loop and exit
- elif user == "p": #if user wants to print the array
- for i in array1:
- print (i) #prints array
- elif user == "a": #user wants to add an item to the array
- y = int(input("What would you like to add to the array?"))
- array1.append(y)
- elif user == "d": #user wants to remove an item from the array
- x = int(input("Which item do you want to remove?"))
- array1.remove(x)
- elif user == "i": #user wants to insert a value at a given place in the array
- w = int(input("Insert what?"))
- v = int(input("Insert where?"))
- array1.insert(v,w)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement