def not_blank(question): """Checks that a user response is not blank""" while True: response = input(question) if response != "": return response print("Sorry, this can't be blank, Please try again.\n") def num_check(question, num_type="float", exit_code=None): """Checks user enter an integer / float that is more than zero (or the optional exit code)""" if num_type == "integer": error = "Opps - please enter an integer more than zero." change_to = int else: error = "Opps - please enter a number more than zero." change_to = float while True: response = input(question).lower() # checks for the exit code if response == exit_code: return response try: response = change_to(response) if response > 0: return response else: print(error) except ValueError: print(error) def get_expenses(exp_type): """Gets variable / fixed expenses and outputs panda (as a string) and a subtotal of the expenses""" #Lists for panda all_items = [] #Expenses dictionary # loop to get expenses while True: item_name = not_blank("Item Name: ") #checks users enter at least one variable expense if (exp_type == "variable" and item_name == "xxx") and len(all_items) == 0: print ("Opps - you have not entered anything. " "You need at least one item. ") continue elif item_name == "xxx": break all_items.append(item_name) #return all items for now so we can check loop return all_items # Main routine starts here # print("Getting Variable Costs...") # variable_expenses = get_expenses("variable") # num_variable = len(variable_expenses) # print(f"You entered {num_variable} items") # print() print("Getting Fixed Costs...") fixed_expenses = get_expenses("fixed") num_fixed = len(fixed_expenses) print(f"You entered {num_fixed} items")