Advertisement
182days

Array Functions

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