I was tasked with developing a program from scratch using the knowledge I gained throughout my Python class. I chose to create an inventory management program for Ghidiu’s Grocery Store, named after my professor. The project required over a week of development and troubleshooting before the program functioned as intended. As this was my first Python program written entirely from scratch, I was very proud of the final result.

Program Description:
The program manages an inventory list for Ghidiu’s Grocery Store and begins by prompting the user for an employee ID number. The user then selects which department inventory file they would like to view or update. The program reads and displays the current contents of the selected file and allows the user to add inventory items until they enter “DONE.” Once completed, the updated inventory list is displayed.

The program also provides a list of valid exit commands. If an incorrect response is entered, a while loop continues prompting the user until a valid command is received. Upon successful exit, the program displays a goodbye message. Since completing this project, I have written several additional scripts in PowerShell and Linux.

Below is the code for the program:

print()
print('*****' "WELCOME TO GHIDIU'S GROCERY INVENTORY PROGRAM" '*****')
print()

import os

def main():
starting_info()
file_reader()
exit()


def starting_info():

# Allows the department_number to be used throughout the code
global department_number

# Allows employee to enter their ID Number. Program then acknowledges them by their number
id_number = input('Please enter your Employee ID Number: ')
print('Access granted, Employee',id_number)
print()

# Allows employee to choose a department inventory list to view or append, and assigns their choice to a variable
print ('Available departments to view:\n(1) Meats\n(2) Frozen\n(3) Produce')
department_number = int(input('Enter the department number: '))
print()

# Uses conditionals (if statements) to acknowledge the selected department
if department_number == 1:
print ('Meat Department Inventory:')
elif department_number == 2:
print ('Frozen Food Inventory:')
elif department_number == 3:
print ('Produce Inventory:')
else:
print ('Department not Found')
quit()


def file_reader():

# Opens the selected file for reading
if department_number == 1:
file = open('Meats.txt', 'r')
elif department_number == 2:
file = open('Frozen.txt', 'r')
elif department_number == 3:
file = open('Produce.txt', 'r')
else:
print()

# Prints the inventory in the file
print(file.read())
print()

# Allows the user to add an item to the selected inventory file
entry = input('What would you like to add to the inventory list? (Type "DONE" when finished.) ')

# These lines open the appropriate file for appending
if department_number == 1:
file = open('Meats.txt', 'a')
elif department_number == 2:
file = open('Frozen.txt', 'a')
elif department_number == 3:
file = open('Produce.txt', 'a')

# These lines append the user input (inventory) to the end of the file. A new line is started with the \n command.
# The "while" command allows the user to enter multiple items, until "DONE" is entered.
while entry != 'DONE':
file.write(entry + '\n')
entry = input('What would you like to add to the inventory list? (Type "DONE" when finished.) ')

file.close

# These lines print the updated inventory list for the file that was just accessed.
print()
print('Here is the updated inventory list:')
if department_number == 1:
file = open('Meats.txt', 'r')
elif department_number == 2:
file = open('Frozen.txt', 'r')
elif department_number == 3:
file = open('Produce.txt', 'r')

print(file.read())


def exit():

# This is a list of allowable commands for exiting.
exit_array = ["E", "e" ,"Exit" ,"exit"]

# This is where the user enters their exit command.
exit_answer = input('If you want to exit the program, then press "E", "e", "Exit", "exit": ' )
print()

# This while statement will keep executing until a response from the list is entered.
while exit_answer not in exit_array:
print('You did not provide a correct response.')
exit_answer = input('Try again... If you want to exit the program, then press "E", "e", "Exit", "exit": ' )
print()

# This is the exit message.
print()
print('Thank you. You have exited the Inventory Program.')
print()


main()

print() print('*****' "WELCOME TO GHIDIU'S GROCERY INVENTORY PROGRAM" '*****') print() import os def main(): starting_info() file_reader() exit() def starting_info(): # Allows the department_number to be used throughout the code global department_number # Allows employee to enter their ID Number. Program then acknowledges them by their number id_number = input('Please enter your Employee ID Number: ') print('Access granted, Employee',id_number) print() # Allows employee to choose a department inventory list to view or append, and assigns their choice to a variable print ('Available departments to view:\n(1) Meats\n(2) Frozen\n(3) Produce') department_number = int(input('Enter the department number: ')) print() # Uses conditionals (if statements) to acknowledge the selected department if department_number == 1: print ('Meat Department Inventory:') elif department_number == 2: print ('Frozen Food Inventory:') elif department_number == 3: print ('Produce Inventory:') else: print ('Department not Found') quit() def file_reader(): # Opens the selected file for reading if department_number == 1: file = open('Meats.txt', 'r') elif department_number == 2: file = open('Frozen.txt', 'r') elif department_number == 3: file = open('Produce.txt', 'r') else: print() # Prints the inventory in the file print(file.read()) print() # Allows the user to add an item to the selected inventory file entry = input('What would you like to add to the inventory list? (Type "DONE" when finished.) ') # These lines open the appropriate file for appending if department_number == 1: file = open('Meats.txt', 'a') elif department_number == 2: file = open('Frozen.txt', 'a') elif department_number == 3: file = open('Produce.txt', 'a') # These lines append the user input (inventory) to the end of the file. A new line is started with the \n command. # The "while" command allows the user to enter multiple items, until "DONE" is entered. while entry != 'DONE': file.write(entry + '\n') entry = input('What would you like to add to the inventory list? (Type "DONE" when finished.) ') file.close # These lines print the updated inventory list for the file that was just accessed. print() print('Here is the updated inventory list:') if department_number == 1: file = open('Meats.txt', 'r') elif department_number == 2: file = open('Frozen.txt', 'r') elif department_number == 3: file = open('Produce.txt', 'r') print(file.read()) def exit(): # This is a list of allowable commands for exiting. exit_array = ["E", "e" ,"Exit" ,"exit"] # This is where the user enters their exit command. exit_answer = input('If you want to exit the program, then press "E", "e", "Exit", "exit": ' ) print() # This while statement will keep executing until a response from the list is entered. while exit_answer not in exit_array: print('You did not provide a correct response.') exit_answer = input('Try again... If you want to exit the program, then press "E", "e", "Exit", "exit": ' ) print() # This is the exit message. print() print('Thank you. You have exited the Inventory Program.') print() main()