-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert.py
45 lines (37 loc) · 1.12 KB
/
insert.py
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
# Original code that we learned about during the PyLadies meetup: https://github.com/saptaks/python-menu-demo
items = []
def insert_item():
name = input("Enter the name of the item: ")
price = input("Enter the price of the item: ")
item = {
"name": name,
"price": price
}
items.append(item)
def display_items():
print("Name\tPrice")
print("___________")
for item in items:
print(f"{item['name']}\t{item['price']}")
def search_items(search_name):
for item in items:
if item['name'] == search_name:
print(f"Item {search_name} found!")
return
print("Item not found!")
def main():
while(True):
print("1. Insert\n2. Show\n3. Search\n4. Exit\n\n")
choice = int(input("Enter choice: "))
if choice == 1:
insert_item()
elif choice == 2:
display_items()
elif choice == 3:
search_name = input("Enter the name of the item you're looking for: ")
search_items(search_name)
elif choice == 4:
break
# This is a way of calling a function and make it global, so that you can call it in different files in your project
if __name__ == '__main__':
main()