Skip to content

Instantly share code, notes, and snippets.

@shardros
Last active September 30, 2016 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shardros/61901ba8a70caf0a12b00b3a61b2a88e to your computer and use it in GitHub Desktop.
Save shardros/61901ba8a70caf0a12b00b3a61b2a88e to your computer and use it in GitHub Desktop.
Some list handling software.
__author__ = "Edwin"
numbers = []
loop = True
try:
# ===========SUBROUTINES==================
def help():
print('To view the list type \'view\''
'\n To add an item type \'add\''
'\n To remove an item type \'remove\''
'\n To find the number of occurrence(s) in the list type \'find\''
'\n To sort any numbers in the list low-high type \'sort\''
'\n To reverse the list type \'reverse\''
'\n To find the length of the list type \'length\''
'\n To find the smallest number type \'min\''
'\n To find the biggest number type \'max\''
'\n To see if a number is in the list type \'in\''
'\n To exit type exit or Ctrl + C can be used at any time')
def add():
new = input("What do you want to append: ")
numbers.append(new)
print("So your list now contains:")
print(numbers)
def view():
print('Your list now contains:')
print(numbers)
def remove():
print('The items in the list are:')
print(numbers)
item = input("What do you want to remove: ")
if item not in numbers:
print("The item is not in the list")
else:
numbers.remove(item)
def find():
word = input("What do you want to find: ")
amount = numbers.count(word)
print("There are " + str(amount) + " occurrence(s) of " + str(word) + " in the list") # sort pural out
def sort():
numbers.sort()
print("All sorted")
print(numbers)
def reverse():
numbers.reverse()
print("The list has been reversed")
print(numbers)
def length():
length = len(numbers)
print("The length of the list is " + str(length))
def minimum():
print("The smallest number is " + min(numbers))
def maximum():
print("The biggest number is " + max(numbers))
def inp():
search = input("What do you want to find: ")
if True == search in numbers:
print(search + " is in the list")
# =========SUBROUTENES END===============
while loop:
task = input("What do you want to do? Type \"help\" for help:- ")
if task == 'help':
help()
elif task == 'add':
add()
elif task == 'view':
view()
elif task == 'remove':
remove()
elif task == 'find':
find()
elif task == 'sort':
sort()
elif task == 'reverse':
reverse()
elif task == 'length':
length()
elif task == 'min':
minimum()
elif task == 'max':
maximum()
elif task == 'in':
inp()
elif task == 'exit':
exit()
else:
print("Invalid return please try again.")
except KeyboardInterrupt:
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment