import pandas import numpy # Functions go here def make_statement(statement, decoration): """Emphasises headings by adding decoration at the start and end""" return f"{decoration * 3} {statement} {decoration * 3}" def string_check(question, valid_ans_list=('yes', 'no'), num_letters=1): """Checks that users enter the full word or the first letter of a word from a list of valid responses""" while True: response = input(question).lower() for item in valid_ans_list: # check if the response is the entire world if response == item: return item # check if it's the first letter elif response == item[:num_letters]: return item print(f"Please choose an option from {valid_ans_list}") def instructions(): make_statement("Instructions", "ℹ️") print(''' For each buyer enter: -Name -Budget This program displays a range of pokemon cards users can purchase within their budget. They can choose how many cards they want, the best value for their budget and then finally purchase. Users can buy multiple cards or can enter (xxx) to leave the code. It will finally show an itemised list of what users chose to purchase ''') 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.") def int_check(question, low, high): """"Checks that users enter an integer is between 2 values""" error = f"Oops - please enter an integer between {low} and {high}." while True: try: # change the response to an integer and check that it's more than zero response = int(input(question)) if low <= response <= high: return response else: print(error) except ValueError: print(error) def currency(x): """Formats numbers as currency ($#.##)""" return "${:.2f}".format(x) # Main Routine goes here # Initialise ticket numbers MAX_SPEND = 3000 tickets_sold = 0 # initialise variables / non-default options for string checker payment_ans = ('cash', 'credit') # lists to hold Pokémon cards all_cards = ["Blastoise (Base)", "Mewtwo (Holo)", "Gen gar (Reverse)", "Charizard (Holo)", "Venusaur (Base)", "Umbreon (Gold Star)", "Espeon (Full Art)", "Lugia (Rainbow Rare)", "Rayquaza (Secret Rare)", "Pikachu (Japanese Promo)"] all_card_costs = [100, 200, 350, 425, 700, 950, 1100, 1600, 2000, 2500] Pokemon_Card_dict = { 'Pokemon Card': all_cards, 'Pokemon Card Price': all_card_costs, } # create dataframe / table from dictionary Pokemon_Card_frame = pandas.DataFrame(Pokemon_Card_dict) # Rearranging index Pokemon_Card_frame.index = numpy.arange(1, len(Pokemon_Card_frame) + 1) # Program main heading print(make_statement("Pokemon Card Comparison", "💲")) name = not_blank("What is your name: ") # Ask user if they want to see the instructions # display them if necessary print() want_instructions = string_check(f"Do you want to see the instructions {name}? ") if want_instructions == "yes": instructions() print() # Ask for their budget between 100 and 3000 budget = int_check("What is your budget? ", 100, 3000) # Loop to get name, age and payment details while budget <= MAX_SPEND: print() # Display menu items print("This is the list of cards we have on offer :") print(Pokemon_Card_frame) # Prompt the user to select a row using the index try: # ask for the user item choice = int_check("Enter the number of the card you would like to choose: ", 1, 10) if choice in Pokemon_Card_frame.index: selected_row = Pokemon_Card_frame.loc[choice] print("You selected:") print(selected_row) else: print("Invalid number. Please choose between 1-10.") continue except ValueError: print("Please enter a valid number.")