Question

*Urgent* I've tried getting help with this a couple times, but nobody has answered my questions,...

*Urgent* I've tried getting help with this a couple times, but nobody has answered my questions, and it's been several days.

####################################################################################

This needs to be Python that works in a Zybooks programming window.

1. Build an ItemToPurchase class with the following specifications:

  • Attributes (3 pts)
  • item_name (string)
  • item_price (float)
  • item_quantity (int)
  • Default constructor (1 pt)
  • Initializes item's name = "none", item's price = 0, item's quantity = 0
  • Method
  • print_item_cost()

Example 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.

Example:

Item 1
Enter the item name:
Chocolate Chips
Enter the item price: 3
Enter the item quantity: 1

Item 2
Enter the item name:
Bottled Water
Enter the item price: 1
Enter the item quantity: 10

3. Add the costs of the two items together and output the total cost.

Example:

TOTAL COST
Chocolate Chips 1 @ $3 = $3
Bottled Water 10 @ $1 = $10
Total: $13

4. Include comments for each line of code in your program explaining what that line of code is doing.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify it with screenshot once. This is the link where I have saved the code too

https://onlinegdb.com/SyUqyifiE

class ItemToPurchase:
#Default constructor
def __init__(self):
# Initializing variables with default values

self.item_name = "none";
  
self.item_price = 0;
  
self.item_quantity = 0;

#print items
def print_item_cost(self):
#Display the item name, quantity and price
print(self.item_name + " " + str(self.item_quantity) + " @ $"
+ str(self.item_price) + " = $"
+ str( self.item_price * self.item_quantity ));

# main function
def main():
#print the item1
print("Item 1 ");

# Creating an object
item1 = ItemToPurchase()
# get item1 details from the user

#=============================================================#
item1.item_name = input('Enter the item name: \n'); #Enter the Name here

item1.item_price = int(input('Enter the item price: \n')); #Enter the Price here
  
item1.item_quantity = int(input('Enter the item quantity: \n'));#Enter the Quantity here
  
#=============================================================#
  
print("\n\nItem 2 ");   

#Creating an object to the class
  
item2 = ItemToPurchase();
  
#get item2 details from the user
  
item2.item_name = input('Enter the item name: \n');
  
item2.item_price = int(input('Enter the item price: \n'));
  
item2.item_quantity = int(input('Enter the item quantity: \n'));
  
print("TOTAL COST ");
#=============================================================#
  
# method to print the details
  
item1.print_item_cost();
  
item2.print_item_cost();
  
# Calculate the cost of items
  
total = (item1.item_price*item1.item_quantity)+(item2.item_price * item2.item_quantity);
  
# Display the total cost
  
print("\nTotal: $" + str(total));

# Calling main method

main();

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
*Urgent* I've tried getting help with this a couple times, but nobody has answered my questions,...
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
  • (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float)...

    (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: Item 1 Enter the item name: Chocolate...

  • 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:...

  • 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,...

  • 9.12 Ch 9 Program: The Evil Register Python 3.7 "The ItemToPurchase class If you haven't done so already, make s...

    9.12 Ch 9 Program: The Evil Register Python 3.7"The ItemToPurchase classIf you haven't done so already, make sure to complete zyLab 9.11 before this one. Otherwise, you will have to implement the ItemToPurchase class from scratch and this zyLab won't make much sense".ItemToPurchase class from zyLab 9.11 refers to:(1) Build the ItemToPurchase class with the following specifications:Attributes (3 pts)item_name (string)item_price (int)item_quantity (int)Default constructor (1 pt)Initializes item's name = "none", item's price = 0, item's quantity = 0Methodprint_item_cost()

  • Please use C Programming language (Not C++) 7.6 LAB*: Warm up: Online shopping cart (Part 1)...

    Please use C Programming language (Not C++) 7.6 LAB*: Warm up: Online shopping cart (Part 1) (1) Create three files to submit: • Item ToPurchase.h - Struct definition and related function declarations • Item ToPurchase.c-Related function definitions • main.c-main function Build the ItemToPurchase struct with the following specifications: • Data members (3 pts) • char itemName • int itemPrice • int itemQuantity • Related functions • MakeltemBlank0 (2 pts) Has a pointer to an item To Purchase parameter. Sets item's...

  • Warm up: Online shopping cart (Part 1)

    8.6 LAB*: Warm up: Online shopping cart (Part 1)(1) Create two files to submit:ItemToPurchase.java - Class definitionShoppingCartPrinter.java - Contains main() methodBuild the ItemToPurchase class with the following specifications:Private fieldsString itemName - Initialized in default constructor to "none"int itemPrice - Initialized in default constructor to 0int itemQuantity - Initialized in default constructor to 0Default constructorPublic member methods (mutators & accessors)setName() & getName() (2 pts)setPrice() & getPrice() (2 pts)setQuantity() & getQuantity() (2 pts)(2) In main(), prompt the user for two items and create...

  • 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...

  • 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)...

  • 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...

  • 8.7 LAB*: Program: Online shopping cart (Part 2)

    8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...

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