Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 2: Food Products in the Stock of a Store AIM: Write a Python class Food for the food products in the stock of a
Exercise 2: Food Products in the Stock of a Store AIM: Write a Python class Food for the food products in the stock of a store. The class has four data attributes for the name, expiry date, price, and number in stock of a food product called name, expDate, price, nstock where name and expDate are of type str, price is of type float, and nStock is of type int. Assume that the data attribute expDate is in the format of dd/mm/yy such as 13/02/23 while the data attribute price is a floating-point value with 1 decimal place. The class Food also has a class attribute called tNum of type int for counting the total number of food products in the stock of the store. It also provides the following methods: (a) __init__(self, name, expDate, price, nStock) for initializing the food product with the given name, expiry date, price, and number in stock, (b) printPrice (self) for displaying the price of the food product, (c) updateprice (self, price) for updating the price of the food product, (d) __- str (self) for returning a string representation of the food product, (e) __repr re_ (self) for returning a string such that eval applied to the string recreates the instance, (f) getTotal () for returning the total number of food products. Here are the sample input and output for using the class Food
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started