-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Data Structures Correction.py
More file actions
90 lines (58 loc) · 3.2 KB
/
Copy pathPython Data Structures Correction.py
File metadata and controls
90 lines (58 loc) · 3.2 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
76
77
78
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 19 19:17:27 2023
@author: lEO
"""
# Objective
# Create a program that allows the user to manage their shopping list. The user should be able to add items to the list, remove items, and view the current list of items.
# Instructions
# Statement:
# Create a list to store the shopping items
# Use a while loop to create a menu of options for the user to add, remove, or view items from the list
# Use a for loop to iterate through the list of items and display them to the user
# Use the range() function to limit the number of items that can be added to the list
# Use the list, tuple, set, and dictionary data structures to store and manipulate the shopping items
# Instructions:
# Create a list named 'shopping_list' to store the items.
# Use a while loop to create a menu of options for the user to add, remove, or view items from the list.
# Use the input() function to prompt the user to make a selection from the menu.
# Use an if-elif-else block to determine the user's selection and perform the corresponding action.
# If the user selects 'add', use the input() function to prompt the user to enter an item to add to the list. Use the range() function to limit the number of items that can be added to the list.
# If the user selects 'remove', use the input() function to prompt the user to enter an item to remove from the list.
# If the user selects 'view', use a for loop to iterate through the list of items and display them to the user.
# Use the list, tuple, set, and dictionary data structures to store and manipulate the shopping items.
# SOLUTION
# Program Variables
shopping_list = []
def view():
print(f"These are the items in your cart: \n{shopping_list}")
def add(item):
thingswesell = ["Mango", "Pineapple", "Apple", "Mango", "Orange", "Lemon", "Strawberry", "Guava", "PawPaw", "Tangerine", "Banana", "Blueberry"]
if item in thingswesell:
shopping_list.append(item)
print("Item has been successfully added.")
else:
print("We don't sell this item. You can try buying something we sell.")
def remove(item):
if item in shopping_list:
shopping_list.remove(item)
print(f"You have removed {item} from your cart.")
else:
print(f"{item} is not in your cart, therefore, it cannot be removed")
# Program Flow
print("Welcome to Leon Fruit Store.\n\nWe sell the following: \n - Mango\n - Pineapple\n - Apple\n - Mango\n - Orange\n - Lemon\n - Strawberry\n - Guava\n - Paw Paw\n - Tangerine\n - Banana\n - Blueberry\n\n")
while True:
question = int(input("\nWhat will you like to do? \nPRESS 1: Add item to cart\nPRESS 2: Remove item from cart\nPRESS 3: View cart\nPRESS 4: Exit\n\nRESPONSE: "))
if question == 4:
print("\nThank you for shopping with us. Goodbye!!!")
break
elif question == 3:
view()
elif question == 2:
item = input("\nWhat item will you like to remove from your cart? \nRESPONSE: ").capitalize().strip()
remove(item)
elif question == 1:
item = input("\nWhich fruit will you like to add to your cart? \nRESPONSE: ").capitalize().strip()
add(item)
else:
print("\nWrong input")