I have this code below:
from classes.database_access import DB_Connect
my_db = DB_Connect('root', '', 'family_bookstore')
print("Welcome to our family bookstore! Select an option from below:")
from functions.show import show_all_books
from functions.add import add_book
from functions.record import record_book_sale
from functions.edit import edit_book_details
from functions.remove import remove_book
def main():
while True:
print("1. Show all books")
print("2. Add a book")
print("3. Record a book sale")
print("4. Edit book details")
print("5. Remove a book")
print("6. Exit program")
option = input("\nSelect an option: ")
if option == '1':
show_all_books()
elif option == '2':
add_book()
elif option == '3':
record_book_sale()
elif option == '4':
edit_book_details()
elif option == '5':
remove_book()
elif option == '6':
print("Exiting program.")
break
else:
print("Invalid option. Please try again.")
if __name__ == "__main__":
main()
I sent it to my professor and this is what he said after I told him about the error that I got in the picture.
"You do not need that main function in your main program. Getting rid of it will let your code access the database variable you created on line 3. Then pass that variable to your functions and you should be OK!"
Is he saying to take out the entire code under the def main() and save it to a separate file to have it imported like I did the ones above and put the my_db function in it or??