Question: bridge - demo.py Rectangle Class ( with comparison code ) In class, we created a very small product class with UPC code, description, and price.
bridgedemo.py
Rectangle Class with comparison code
In class, we created a very small product class with UPC code, description, and price. This code creates two products, then prints which has the smaller price.
The code illustrates the usage of initstr and the comparison functions eq and gt There are six total comparison functions, but you only need to implement three eq either gt or lt either ge or le
class Productobject:
# UPC,Description,Price
def initselfUPC,desc,price:
self.UPC UPC
self.description desc
self.price price
def strself:
s self.UPC self.description
s strselfprice
return s
def gtselfother:
return self.price other.price
def eqselfother:
return self.price other.price
p Product"Green Beans",
p Product Gallon Milk",
printp
printp
printp p
printp p
if p p:
printpdescription,"is less expensive"
else:
printpdescription,"is less expensive"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
