Question

Hi, can someone offer input on how to address these 4 remain parts the zybook python...

Hi, can someone offer input on how to address these 4 remain parts the zybook python questions?  

4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart)

Your output

ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line

5: Test that get_cost_of_cart() returns 10 (ShoppingCart)

Your output

ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 9, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line

# Type code here

# code 1

# obtaining 21 of the 29 points

class ItemToPurchase:

    def __init__(self, item_name='none', item_description='none', item_price=0, item_quantity=0):

        self.item_name = item_name

        self.item_description = item_description

        self.item_price = item_price

        self.item_quantity = item_quantity

    def print_item_cost(self):

        print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self.item_price) + " = $" + str(

            self.item_price * self.item_quantity))

    def print_item_description(self):

        string = '{}: {}'.format(self.item_name, self.item_description)

        print(string, end='\n')

        return string

   

class ShoppingCart:

    def __init__(self, customer_name='none', current_date='January 1, 2016', cart_items=[]):

        self.customer_name = customer_name

        self.current_date = current_date

        self.cart_items = cart_items

    def add_item(self,ItemToPurchase):

        print('\nADD ITEM TO CART', end='\n')

        item_name = str(input('Enter the item name:\n'))

        item_description = str(input('Enter the item description:\n'))

        item_price = int(input('Enter the item price:\n'))

        item_quantity = int(input('Enter the item quantity:\n'))

        self.cart_items.append(ItemToPurchase(item_name, item_description, item_price, item_quantity))

       

    def remove_item(self):

        print('REMOVE ITEM FROM CART', end='\n')

        string = str(input('Enter name of item to remove:\n'))

        i = 0

        for item in self.cart_items:

            if (item.item_name == string):

                del self.cart_items[i]

                i += 1

                flag = True

                break

            else:

                flag = False

        if (flag == False):

            print('Item not found in cart. Nothing removed.')

    def modify_item(self, ItemToPurchase):

        print('CHANGE ITEM QUANTITY', end='\n')

        name = str(input('Enter the item name:\n'))

        for item in self.cart_items:

            if (item.item_name == name):

                quantity = int(input('Enter the new quantity:\n'))

                item.item_quantity = quantity

                flag = True

                break

            else:

                flag = False

        if (flag == False):

            print('Item not found in cart. Nothing modified.')

    def get_num_items_in_cart(self):

        num_items = 0

        for item in self.cart_items:

            num_items = num_items + item.item_quantity

        return num_items

    def get_cost_of_cart(self):

        total_cost = 0

        cost = 0

        for item in self.cart_items:

            cost = (item.item_quantity * item.item_price)

            total_cost += cost

        return total_cost

    def print_total(self):

        total_cost = self.get_cost_of_cart()

        self.output_cart()

    def print_descriptions(self):

        print('OUTPUT ITEMS\' DESCRIPTIONS')

        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_date), end='\n')

        print('\nItem Descriptions', end='\n')

        for item in self.cart_items:

            print('{}: {}'.format(item.item_name, item.item_description), end='\n')

    def output_cart(self):

        new = ShoppingCart()

        print('OUTPUT SHOPPING CART', end='\n')

        print('{}\'s Shopping Cart - {}'.format(self.customer_name, self.current_date), end='\n')

        print('Number of Items:', new.get_num_items_in_cart(), end='\n\n')

        total_cost = 0

        if (new.get_num_items_in_cart() == 0):

            print('SHOPPING CART IS EMPTY\n')

            print('Total: $0')

        else:

            for item in self.cart_items:

                print('{} {} @ ${} = ${}'.format(item.item_name, item.item_quantity,

                                                 item.item_price, (item.item_quantity * item.item_price)), end='\n')

                total_cost += (item.item_quantity * item.item_price)

            print('\nTotal: ${}'.format(total_cost), end='\n')

       

def print_menu(ShoppingCart, customer_name, current_date):

    newCart = ShoppingCart(customer_name, current_date)

    customer_Cart = newCart

    # declare the string menu

    menu = ('\nMENU\n'

            'a - Add item to cart\n'

            'r - Remove item from cart\n'

            'c - Change item quantity\n'

            'i - Output items\' descriptions\n'

            'o - Output shopping cart\n'

            'q - Quit\n')

    command = ''

    string = ''

    while (command != 'q'):

        print(menu, end='\n')

        command = input('Choose an option:\n')

        while (command != 'a' and command != 'o' and command != 'i' and command != 'r'

               and command != 'c' and command != 'q'):

            command = input('Choose an option:\n')

        if (command == 'a'):

            customer_Cart.add_item(ItemToPurchase)

        if (command == 'o'):

            customer_Cart.output_cart()

        if (command == 'i'):

            customer_Cart.print_descriptions()

        if (command == 'r'):

            customer_Cart.remove_item()

        if (command == 'c'):

            customer_Cart.modify_item(ItemToPurchase)

def main():

    customer_name = str(input('Enter customer\'s name:\n'))

    current_date = str(input('Enter today\'s date:\n'))

    print('\nCustomer name:', customer_name, end='')

    print('\nToday\'s date:', current_date, end='\n')

    print_menu(ShoppingCart, customer_name, current_date)

if __name__ == '__main__':

    main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I ran your program in python IDLE and it is working fine with the different correct type of input values of shopping cart item. However, I found that if wrong value of item price or item quantity are used in the test data file, the program crashes. See the error as below.
Check your test data, you may get some clue of error.

If error is not removed still, let me know your test data please.

Add a comment
Know the answer?
Add Answer to:
Hi, can someone offer input on how to address these 4 remain parts the zybook python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

  • 7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consid...

    7.11 LAB: Online shopping cart - Part 2 This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase namedtuple to contain a new attribute. (2 pts) item_description (string) - Set to "none" in the construct_item() function Implement the following function with an ItemToPurchase as a parameter. print_item_description() - Prints item_name and item_description attribute for an ItemToPurchase namedtuple. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz....

  • Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...

    Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!! This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • 11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications:...

    11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex:...

  • 11.12 LAB*: Program: Online shopping cart (continued) This program extends the earlier "Online shopping cart" pr...

    11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...

  • Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run prope...

    Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase:     def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'):         self.nameitem = nameitem         self.item_prc = item_prc         self.item_quntity = item_quntity         self.item_descrp = item_descrp     def print_itemvaluecost(self):              string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc))         valuecost = self.item_quntity * self.item_prc         return string, valuecost     def print_itemdescription(self):         string = '{}: {}'.format(self.nameitem, self.item_descrp)         print(string , end='\n')         return string class Shopping_Cart:     #Parameter...

  • Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to...

    Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase:     def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'):         self.nameitem = nameitem         self.item_prc = item_prc         self.item_quntity = item_quntity         self.item_descrp = item_descrp     def print_itemvaluecost(self):              string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc))         valuecost = self.item_quntity * self.item_prc         return string, valuecost     def print_itemdescription(self):         string...

  • in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Po...

    in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Pop(self): return self.items.pop() def Display(self): for i in reversed(self.items): print(i,end="") print() s = My_Stack() #taking input from user str = input('Enter your string for palindrome checking: ') n= len(str) #Pushing half of the string into stack for i in range(int(n/2)): s.Push(str[i]) print("S",end="") s.Display() s.Display() #for the next half checking the upcoming string...

  • Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - dis...

    Explain what the code is doing line from line explanations please or summarize lines with an explanation def displayCart(): #displays the cart function """displayCart function - displays the items in the cart ---------------------------------------------------------------------""" import os os.system('clear') print("\n\nCart Contents:") print("Your selected items:", cart) def catMenu(): #function that displays the category menu """catMenu function - displays the categories user picks from ---------------------------------------------------------------------""" import os os.system('clear') print(""" 1 - Books 2 - Electronics 3 - Clothing d - display cart contents x -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT