Skip to content

Commit d13967a

Browse files
Code update
1 parent 083075c commit d13967a

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

Back-end Project - Shop Cart/English/Functions.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
def clear():
66
if system_os() == "Windows":
77
system('cls')
8+
89
else:
910
system('clear')
1011

@@ -13,30 +14,37 @@ def show_content(container):
1314
for product in container:
1415

1516
if type(container) == dict:
16-
1717
print("\n -{}, ${}".format(product, container[product]))
1818

1919
elif type(container) == list:
20-
2120
print("\n -{} ${}".format(product, products[product]))
2221

2322

2423
def bags():
25-
bag = (input("Do you need any bags? (5$ each) (Yes/No)\n>")).capitalize()
26-
2724
global bags_amount
2825

29-
if bag == "Yes":
30-
bags_amount = int(input("\nHow many bags you gonna need?\n>"))
26+
while True:
27+
bag = (input("Do you need any bags? (5$ each) (Yes/No)\n>")).capitalize()
28+
29+
if bag == "Yes":
3130

32-
if bags_amount == ValueError:
33-
print("\nError. Please introduce a number.")
31+
while True:
32+
33+
try:
34+
bags_amount = int(input("\nHow many bags you gonna need?\n>"))
35+
36+
except ValueError:
37+
print("\nError. Please introduce a number.")
38+
39+
else:
40+
return bags_amount
41+
42+
elif bag == "No":
43+
bags_amount = 0
44+
break
3445

35-
elif bag == "No":
36-
bags_amount = 0
37-
38-
else:
39-
print('\nError. Answer "Yes" or "No"')
46+
else:
47+
print('\nError. Answer "Yes" or "No"')
4048

4149

4250
def show_price(cart):
@@ -46,7 +54,6 @@ def show_price(cart):
4654
bags_price = (bags_amount * 5)
4755

4856
for producto in cart:
49-
5057
total += products[producto]
5158

5259
tax = (total + bags_price) * 0.21
@@ -57,4 +64,4 @@ def show_price(cart):
5764
Subtotal: {}$
5865
TAX (21%)= ${:.3f}
5966
60-
-TOTAL + TAX= ${:.2f}""".format(bags_amount, bags_price, total, tax, total + tax + bags_price))
67+
-TOTAL + TAX= ${:.2f}""".format(bags_amount, bags_price, total, tax, total + tax + bags_price))
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#-------------Program imports------------------------
1+
#-------------Imports del programa------------------------
22

33
from Warehouse import products
44
from Functions import *
55

6-
#-------------Program--------------------------------
6+
#-------------Programa------------------------------------
77

88
clear()
99
print("Welcome to the supermarket in console")
@@ -14,21 +14,19 @@
1414

1515
show_content(products)
1616

17-
print("\nPlease, choose the product you want to add to the cart (One at the time)\n")
17+
print("\nPlease, choose the product you want to add to the cart (One at the time)")
1818

1919
first_product = (input(">")).capitalize()
2020

2121
while first_product not in products.keys():
22-
2322
print("\nProduct not found, please enter one of the products displayed on the window.")
2423
first_product = (input(">")).capitalize()
2524

2625
cart.append(first_product)
2726

28-
print("-------------------------------------\n")
27+
print("\n-------------------------------------\n")
2928

3029
while True:
31-
3230
choice = (input("Do you want to add another product?(Yes/No)\n>")).capitalize()
3331

3432
if choice == "Yes":
@@ -38,10 +36,9 @@
3836

3937
print("\nPlease, choose which product you want to add to the cart (one at the time):")
4038

41-
other_products = (input("\n>")).capitalize()
42-
39+
other_products = (input(">")).capitalize()
40+
4341
while other_products not in products.keys():
44-
4542
print("\nProduct not found, please enter one of the products displayed on the window.")
4643
other_products = (input(">")).capitalize()
4744

@@ -50,13 +47,11 @@
5047
print("-------------------------------------\n")
5148

5249
elif choice == "No":
53-
5450
print("-------------------------------------\n")
55-
5651
break
5752

5853
else:
59-
print('Error. Please enter "Yes" or "No"')
54+
print('\nError. Please enter "Yes" or "No"')
6055

6156
bags()
6257

@@ -68,4 +63,4 @@
6863

6964
show_price(cart)
7065

71-
print("\nThank you very much!\n")
66+
print("\nThank you very much!\n")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy