import os dirPath = os.path.dirname(os.path.realpath(__file__)) def make_book( isbn:int, title:str, authors:list, genre:str, rating:float, price:float )->dict: return { 'isbn' : isbn, 'title' : title, 'authors' : authors, 'genre' : genre, 'rating' : rating, 'price' : price } def read_file(file): file.readline() # Skip the first row in csv data = file.readlines() # Get the rest of rows as list books = [] # Create list to store dictionaries for line in data: # Iterate through rows line = line.strip().split(',') # Split row into list isbn, title, authors, genre, rating, price = ( # Assign and typecast data. int(line[0]), line[1], [line[2]], line[3], float(line[4]), float(line[5]) ) # Add dictionary to list books.append(make_book(isbn, title, authors, genre, rating, price)) return books with open(dirPath + '/books.csv') as file: books = read_file(file) cart = [] for x in range(3): cart.append(books[0]) def get_total(cart:list)->float: total = 0 for item in cart: total += item['price'] tax = 0.06 * total return total + tax print(get_total(cart))