Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / I am working on a project in Codio (for Python) I am able to get most of the output, but not all of the output that is needed

I am working on a project in Codio (for Python) I am able to get most of the output, but not all of the output that is needed

Computer Science

I am working on a project in Codio (for Python) I am able to get most of the output, but not all of the output that is needed. I am not sure what I am missing in my codes.

 

Code:

 

grocery_item = {} #empty dictionary 

grocery_history = [] #empty list 

#grocery_history= [{'Name': 'milk', 'Quantity': int(1), 'Cost': float(2.99)},

                  #{'Name': 'eggs', 'Quantity': int(2), 'Cost': float(3.99)},

                  #{'Name': 'onions', 'Quantity': int(4), 'Cost': float(0.79)}]

                 

#stop = False

#stop = True

response = True 

 

#while not stop: #while loop starting, should not = q 

#while stop != 'q':  

while response != 'q': 

  item_name = input("Item name:n ") #taking item name that is input 

  item_quantity = input("Quantity purchased: n") #taking quantity of item    

  item_cost = input("Price per item: n") #taking cost of (1)item 

  

  grocery_item['Name']= item_name

  grocery_item['Quantity'] = int(item_quantity)#int always a whole number 

  grocery_item['Cost']= float(item_cost) #float due to cost being a decimal

  

  grocery_history.append(grocery_item.copy())

    

  response = input("Would you like to enter another item? nType 'c' for continue or 'q' to quit: n")

  #if response == 'q':

      #stop = True 

      

 grand_total = 0 

 

for index, item  in enumerate(grocery_history): 

 

  item_total = item['Quantity'] * item['Cost']

  

  grand_total= grand_total + item_total

  

 

item_total= 0 

 

print("%d %s @ $%.2f ea $%.2f" %(item['Quantity'], item['Name'], item['Cost'], item_total))

print("Grand total: $%.2f" % grand_total )

 

Expected Output:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

1 milk @ $2.99 ea $2.99

2 eggs @ $3.99 ea $7.98

4 onions @ $0.79 ea $3.16

Grand total: $14.13

 

My Output:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

Item name:

Quantity purchased:

Price per item:

Would you like to enter another item?

Type 'c' for continue or 'q' to quit:

4 onions @ $0.79 ea $0.00

Grand total: $14.13

 

 

I am very new to Python, if able to please explain in detail. Thank you kindly!

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions