samedi 18 mai 2019

i'm trying to call a funtion inside this if statement but the terminal is give me error " NameError: name 'introduceSelf' is not defined""

I'm trying to call the funtion "introduceSelf" inside the if statement but it is giving me NameError: name 'intoduceSelf' is not defined. Help

class Robot:
    kind = "robot"

def __init__(self, name, color, weight):
    self.name = name
    self.color = color
    self.weight = str(weight)

def introduceSelf(self, temp):
    print("i am a " + temp.name)

r1 = Robot("Tom", "blue", 30)
r2 = Robot("jerry", "red", 20)

n = input("which robot are you looking for ")

if n =="r1":
    temp = r1
    introduceSelf()

if n=="r2":
    temp = r2
    introduceSelf()   
else:
    print("No robot found")

i expect it to run the code in the funtion introduceSelf.

Aucun commentaire:

Enregistrer un commentaire