class Bike:
def __init__(self, speed):
self.speed = speed
def speed(self):
if (self.speed) > 120:
print("You are driving fast.")
else:
print("You are diving safely.")
bike1 = Bike(32)
bike1.speed()
It is showing:
Traceback (most recent call last):
File "C:\Users\Syed\PycharmProjects\Muneer Python\Python Beginner Mosh\App.py", line 10, in <module>
bike1.speed()
TypeError: 'int' object is not callable
I tried using a variable x as self.speed in speed function, but still it is not working. How to fix it?
self.speed=speedthis overwrites the methodspeed. Use different names for the integer variable and the method.self.speedwithself.speed_varor anything other namespeed()method would be better renamed asstatus()or the like. Most people would expectspeedto be numeric. In programming in general and OOP in particular, naming matters.