Python - Class methods with input -
how can create method in class user input?
what argument should pass when calling method ?
class student: def __init__(self): self._name = '' def getname(self): return self._name def setname(self, newname): newname = input ('inserire nome:') self._name = newname studente = student() studente.setname(newname)
this should work:
class student: def __init__(self): self._name = '' def getname(self): return self._name def setname(self, newname): self._name = newname studente = student() newname = input('inserire nome:') studente.setname(newname)
you defining input inside method passing variable outside. variable newname
wasn't defined outside. let me know if doesn't work. haven't tested it, seems conspicuous error here.
Comments
Post a Comment