-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshoppinglist.py
More file actions
75 lines (62 loc) · 2.31 KB
/
shoppinglist.py
File metadata and controls
75 lines (62 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Create the main menu
def mainMenu():
while True:
print()
print('''### SHOPPING LIST ###
Select a number for the action that you would like to do:
1. View shopping list
2. Add item to shopping list
3. Remove item from shopping list
4. Check if item is on shopping list
5. How many items on shopping list
6. Clear shopping list
''')
selection = input("Make your selection: ") # Ask the user to make a selection
# Determine which action to perform based on the user's selection
if selection == "1":
displayList()
elif selection == "2":
addItem()
elif selection == "3":
removeItem()
elif selection == "4":
checkItem()
elif selection == "5":
listLength()
elif selection == "6":
clearList()
else:
print("You did not make a valid selection.")
shopping_list = ["apples", "bananas", "carrots", "potatoes"] # Add a few items to the shopping list
# Displays all items on the shopping list
def displayList():
print()
print("--- SHOPPING LIST ---")
for i in shopping_list:
print("* " + i)
# Adds an item to the shopping list
def addItem():
item = input("Enter the item you wish to add to the shopping list: ")
shopping_list.append(item)
print(item + " has been added to the shopping list.")
# Remove an item from the shopping list
def removeItem():
item = input("Enter the item you wish to remove from the shopping list: ")
shopping_list.remove(item)
print(item + " has been removed from the shopping list.")
# Check to see if a particular item is on the shopping list
def checkItem():
item = input("What item would you like to check on the shopping list: ")
if item in shopping_list:
print("Yes, " + item + " is on the shopping list.")
else:
print("No, " + item + " is not on the shopping list.")
# How many items are on the shopping list
def listLength():
print("There are", len(shopping_list), "items on the shopping list.")
# Remove everything from the shopping list
def clearList():
shopping_list.clear()
print("The shopping list is now empty.")
# Run the function mainMenu - which will run our app
mainMenu()