|
| 1 | +''' |
| 2 | +Grocery List Creator Python program |
| 3 | +
|
| 4 | +Created by Joseph C. Richardson |
| 5 | +
|
| 6 | +This is a full functional grocery list Python program example to add to my Python book. |
| 7 | +Feel free to copy this Python program example if you like. See what you can do with it. |
| 8 | +Please enjoy. |
| 9 | +''' |
| 10 | +import os |
| 11 | + |
| 12 | +title='title grocery list creator' |
| 13 | +clear_screen='cls' |
| 14 | +single_line_break='\n' |
| 15 | +double_line_break='\n\n' |
| 16 | +indent=' '*2 |
| 17 | +dot_space='.'*3 |
| 18 | +create_list='vgl' |
| 19 | +enter=0 |
| 20 | +decimal_point=100 |
| 21 | +button1='y' |
| 22 | +button2='n' |
| 23 | + |
| 24 | +sentence=[ |
| 25 | +f'{single_line_break}{indent}grocery list creator', # index 0 |
| 26 | + |
| 27 | +f'''{double_line_break}{indent}Press "Enter" after each grocery list item typed. |
| 28 | +{indent}Type "vgl", then press "Enter" to view your grocery list output.''', # index 1 |
| 29 | + |
| 30 | +f'{double_line_break}{indent}Please type your grocery list items: ', # index 2 |
| 31 | + |
| 32 | +f'{double_line_break}{indent}Please type your grocery list item price: $', # index 3 |
| 33 | + |
| 34 | +f'{double_line_break}{indent}You have', # indext 4 |
| 35 | + |
| 36 | +'items in your grocery list.', # index 5 |
| 37 | + |
| 38 | +f'{double_line_break}{indent}Here is your grocery list output:', # index 6 |
| 39 | + |
| 40 | +f'{single_line_break}{indent}Your grocery list total:', # index 7 |
| 41 | + |
| 42 | +f'''{single_line_break}{indent}Do you wish to add more items to your grocery list? |
| 43 | +{single_line_break}{indent}Press "y" or "n" to confirm: ''', # index 8 |
| 44 | + |
| 45 | +f'{single_line_break}{indent}thank you for choosing grocery list creator... \ |
| 46 | +press enter to exit.', # index 9 |
| 47 | +] |
| 48 | + |
| 49 | +user_input_item_data=[ ] |
| 50 | +user_input_price_data=[ ] |
| 51 | + |
| 52 | +user_input_item_data.append(enter) |
| 53 | +user_input_price_data.append(enter) |
| 54 | + |
| 55 | +os.system(title.title()) |
| 56 | + |
| 57 | +def items_list(): |
| 58 | + |
| 59 | + while True: |
| 60 | + os.system(clear_screen) |
| 61 | + grocery_list=input(sentence[0].title() |
| 62 | + +sentence[1]+sentence[2]).strip() |
| 63 | + user_input_item_data.append(grocery_list) |
| 64 | + |
| 65 | + if grocery_list==create_list: |
| 66 | + user_input_item_data.remove(create_list) |
| 67 | + item=user_input_item_data |
| 68 | + item.remove(enter) |
| 69 | + break |
| 70 | + |
| 71 | + try: |
| 72 | + os.system(clear_screen) |
| 73 | + item_price=float(input(sentence[0].title() |
| 74 | + +sentence[1]+sentence[3]).strip()) |
| 75 | + user_input_price_data.append(item_price) |
| 76 | + except ValueError: |
| 77 | + user_input_price_data.append(0) |
| 78 | + |
| 79 | + while True: |
| 80 | + os.system(clear_screen) |
| 81 | + print(sentence[0].title()+sentence[6]) |
| 82 | + |
| 83 | + try: |
| 84 | + x=1 |
| 85 | + for i in item: |
| 86 | + print(f'{single_line_break}{indent}{x}) {dot_space} {i} \ |
| 87 | +${user_input_price_data[x]/decimal_point}'.title()) |
| 88 | + x+=1 |
| 89 | + except IndexError: |
| 90 | + item.remove(enter) |
| 91 | + |
| 92 | + total_sum=user_input_price_data |
| 93 | + |
| 94 | + print(f'{sentence[7]} ${sum(total_sum)/decimal_point}', |
| 95 | + sentence[4],len(item),sentence[5]) |
| 96 | + |
| 97 | + grocery_list=input(sentence[8]).lower().strip() |
| 98 | + |
| 99 | + user_input_item_data.append(enter) |
| 100 | + |
| 101 | + if grocery_list==button1: |
| 102 | + items_list() |
| 103 | + break |
| 104 | + elif grocery_list==button2: |
| 105 | + break |
| 106 | + |
| 107 | +items_list() |
| 108 | +os.system(clear_screen) |
| 109 | +input(sentence[9].title()) |
0 commit comments