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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -