Skip to content

Commit 086082d

Browse files
Grocery List Creator
This is the Python basics to creating a Grocery List Creator Python program example.
1 parent 3c9c99c commit 086082d

File tree

1 file changed

+75
-36
lines changed

1 file changed

+75
-36
lines changed

Grocery List Creator.py

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,119 @@
11
'''
2+
Grocery List Creator Python program
3+
4+
Created by Joseph C. Richardson
5+
26
This is a full functional grocery list Python program example to add to my Python book.
37
Feel free to copy this Python program example if you like. See what you can do with it.
4-
As time rolls on, I will make this an actual, working program, which the user can place
5-
the price of a grocery list item, while it keeps track of what you will be spending at the
6-
store. The user will also be able to clear the list items or clear just one single list item,
7-
while the price part of the program will work as addition and subtraction of list pricing,
8-
via items added or removed from the shopping list. You are all welcome to copy this
9-
program and make it do and be anything you like. Maybe try and create the list, such as
10-
what I want to make it do down the road. Please enjoy.
8+
Please enjoy.
119
'''
1210
import os
1311

14-
title='title Grocery List Creator'
12+
text_colours=(
13+
'\x1b[31m', # index 0 = red
14+
'\x1b[32m', # index 1 = green
15+
'\x1b[33m', # index 2 = yellow
16+
'\x1b[34m', # index 3 = blue
17+
'\x1b[35m', # index 4 = purple
18+
'\x1b[36m', # index 5 = cyan
19+
'\x1b[37m' # index 6 = white
20+
)
21+
22+
title='title grocery list creator'
1523
clear_screen='cls'
1624
single_line_break='\n'
1725
double_line_break='\n\n'
1826
indent=' '*2
1927
dot_space='.'*3
2028
create_list='vgl'
29+
enter=0
30+
decimal_point=100
2131
button1='y'
2232
button2='n'
23-
enter=''
24-
25-
os.system(title)
2633

2734
sentence=[
28-
f'{single_line_break}{indent}Grocery List Creator', # index 0
35+
f'{single_line_break}{indent}grocery list creator', # index 0
2936

3037
f'''{double_line_break}{indent}Press "Enter" after each grocery list item typed.
3138
{indent}Type "vgl", then press "Enter" to view your grocery list output.''', # index 1
3239

3340
f'{double_line_break}{indent}Please type your grocery list items: ', # index 2
3441

35-
f'{single_line_break}{indent}You have', # indext 3
42+
f'{double_line_break}{indent}Please type your grocery list item price: $', # index 3
43+
44+
f'{double_line_break}{indent}You have', # indext 4
3645

37-
'items in your grocery list.', # index 4
46+
'items in your grocery list.', # index 5
3847

39-
f'{double_line_break}{indent}Here is your grocery list output:', # index 5
48+
f'{double_line_break}{indent}Here is your grocery list output:', # index 6
49+
50+
f'{single_line_break}{indent}Your grocery list total:', # index 7
4051

4152
f'''{single_line_break}{indent}Do you wish to add more items to your grocery list?
42-
{indent}Press "y" or "n" to confirm: ''' # index 6
53+
{single_line_break}{indent}Press "y" or "n" to confirm: ''', # index 8
54+
55+
f'{single_line_break}{indent}thank you for choosing grocery list creator... \
56+
press enter to exit.', # index 9
4357
]
4458

45-
user_data=set()
46-
user_data.add(enter)
59+
user_input_item_data=[ ]
60+
user_input_price_data=[ ]
61+
62+
user_input_item_data.append(enter)
63+
user_input_price_data.append(enter)
64+
65+
os.system(title.title())
4766

4867
def items_list():
68+
4969
while True:
5070
os.system(clear_screen)
51-
grocery_list=input(sentence[0]\
71+
grocery_list=input(text_colours[5]+sentence[0].title()
5272
+sentence[1]+sentence[2]).strip()
53-
user_data.add(grocery_list)
73+
user_input_item_data.append(grocery_list)
74+
5475
if grocery_list==create_list:
55-
user_data.remove(create_list)
56-
convert=list(user_data)
57-
convert.remove(enter)
58-
convert.sort()
76+
user_input_item_data.remove(create_list)
77+
item=user_input_item_data
78+
item.remove(enter)
5979
break
6080

81+
try:
82+
os.system(clear_screen)
83+
item_price=float(input(text_colours[5]+sentence[0].title()
84+
+sentence[1]+sentence[3]).strip())
85+
user_input_price_data.append(item_price)
86+
except ValueError:
87+
user_input_price_data.append(0)
88+
6189
while True:
6290
os.system(clear_screen)
63-
print(sentence[0]+sentence[5])
64-
65-
x=1
66-
for i in convert:
67-
print(f'{single_line_break}{indent}{x}) {dot_space}',i.title())
68-
x+=1
69-
70-
print(sentence[3],len(convert),sentence[4])
71-
grocery_list=input(sentence[6]).lower().strip()
91+
print(sentence[0].title()+sentence[6])
92+
93+
try:
94+
x=1
95+
for i in item:
96+
print(f'{single_line_break}{indent}{x}) {dot_space} {i} \
97+
${user_input_price_data[x]/decimal_point}'.title())
98+
x+=1
99+
except IndexError:
100+
item.remove(enter)
101+
102+
total_sum=user_input_price_data
72103

104+
print(f'{sentence[7]} ${sum(total_sum)/decimal_point}',
105+
sentence[4],len(item),sentence[5])
106+
107+
grocery_list=input(sentence[8]).lower().strip()
108+
109+
user_input_item_data.append(enter)
110+
73111
if grocery_list==button1:
74-
items_list()
112+
items_list()
75113
break
76114
elif grocery_list==button2:
77115
break
78-
116+
79117
items_list()
80-
input('end')
118+
os.system(clear_screen)
119+
input(sentence[9].title())

0 commit comments

Comments
 (0)