
how can i fix my code to get the expected output ?
my code :
main.py:
import csv
from ItemToPurchase import ItemToPurchase, Item
def main():
items = {}
with open('available_items.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
item_id = row['item_id']
description = row['description']
price = float(row['price'])
items[item_id] = Item(description, price)
cart = []
while True:
print('Enter the id of an item you wish to purchase:')
item_id = input().lower()
if item_id in items:
item = items[item_id]
print('Enter the quantity of {} to purchase:'.format(item.description))
quantity = int(input())
if quantity > 0:
i = ItemToPurchase(item, quantity)
cart.append(i)
i.print()
else:
print('Invalid quantity')
elif item_id == 'q':
break
else:
print('Invalid item id')
total = 0
for item in cart:
item.print()
total += item.cost()
print('\n Total $ {:>6.2f}'.format(total))
if __name__ == '__main__':
main()
ItemToPurchase.py:
from collections import namedtuple
Item = namedtuple('Item', ('description', 'price',))
class ItemToPurchase:
def __init__(self, item:Item, quantity:int):
self.item = item
self.quantity = quantity
def cost(self):
return self.quantity * self.item.price
def print(self):
desc = self.item.description
price = self.item.price
qty = self.quantity
total = self.cost()
print(' {} {:<25} @ $ {:0.2f} ea. = ${:>6.2f}'.format(qty, desc, price, total))


Step by stepSolved in 2 steps

- The shape class variable is used to save the shape of the forestfire_df dataframe. Save the result to ff_shape. # TODO 1.1 ff_shape = print(f'The forest fire dataset shape is: {ff_shape}') todo_check([ (ff_shape == (517,13),'The shape recieved for ff_shape did not match the shape (517, 13)') ])arrow_forwardWhich of the following statements can be used to insert an array of documents into a collection? A. Any of the other answers will work B. > var arrayname = [{},{},{}];> db.collectionname.insert(arrayname); C. > db.collectionname.insertMany([{},{},{}]); D. > var arrayname = [{},{},{}];> db.collectionname.insertMany(arrayname);arrow_forwardIn python: student_dict is a dictionary with students' name and pedometer reading pairs. A new student is read from input and added into student_dict. For each student in student_dict, output the student's name, followed by "'s pedometer reading: ", and the student's pedometer reading. Then, assign average_value with the average of all the pedometer readings in student_dict..arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





