I have written the following python code:
class Smartphone:
def __init__(self, price):
self.price = price
def price():
return price
def lowest_price(phones):
cheapest = phones[0]
for phone in phones:
if phone.price() < cheapest.price():
cheapest = phone
return cheapest
if __name__ == "__main__":
p1 = Smartphone(950)
p2 = Smartphone(1950)
phones = [p1, p2]
cheapest = lowest_price(phones)
When I run this code, I get the following error:
Traceback (most recent call last):
File "test.py", line 21, in <module>
cheapest = lowest_price(phones)
File "test.py", line 12, in lowest_price
if phone.price() < cheapest.price():
TypeError: 'int' object is not callable
What does that mean and how do I resolve it? Also price could be a float too.