26 lines
622 B
Python
26 lines
622 B
Python
# Declare list variable
|
|
list = []
|
|
|
|
# Function adds value (String) to list
|
|
def add_item(item):
|
|
list.append(item)
|
|
|
|
# Function prints the list out with amount of items
|
|
def view_list():
|
|
print(f"You have {len(list)} items in your shopping list")
|
|
print(list)
|
|
|
|
# While loop that ends when n is inputed and breaks the loop
|
|
while(1):
|
|
# Get user input to continue or not
|
|
ans = input("Add item to list?(y/n): ")
|
|
|
|
# Checks if user wants to add new item to list
|
|
if (ans.lower() == "y"):
|
|
user_item = input("Enter item name: ")
|
|
add_item(user_item)
|
|
else:
|
|
view_list()
|
|
break
|
|
|