Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 14, 2017 21:34
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 codecademydev/07fca53d160f12caa7de7a0fbe4e40aa to your computer and use it in GitHub Desktop.
Save codecademydev/07fca53d160f12caa7de7a0fbe4e40aa to your computer and use it in GitHub Desktop.
Codecademy export
# make a list to hold onto our items
import os
shopping_list = []
def open_save():
file_name = input("""Type your shopping list file name
(add .txt to end of name): """)
try:
with open(file_name, 'w') as file_name:
for items in shopping_list:
file_name.write(str(items) + "\n")
except:
print("try again")
def close_file():
try:
os.system('TASKKILL /F /IM shopping_list.txt')
except Exception as e:
print(e)
def show_help():
# print out instructions on how to use the app
print("What should we pick up at the store?")
print("""
Enter 'DONE' to stop adding items.
Enter 'HELP' for this help.
Enter 'SHOW' to see your current list.
""")
def show_list():
# print out the list
print("Here's your list:")
for item in shopping_list:
print(item)
def add_to_list(new_item):
# add new items to our list
shopping_list.append(new_item)
print("Added {}. List now has {} items."\
.format(new_item, len(shopping_list)))
open_save()
show_help()
while True:
# ask for new items
new_item = input("> ")
# be able to quit the app
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
add_to_list(new_item)
show_list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment