data entry with (input) in 3x python

2

I have this class code that runs without any problem, I want to do the data entry using input function and then visualize it with print or return , but I could not do it, it is unconfigured when I try.

I would appreciate guidance on the subject. How can I achieve it?

#SuperClase, Clase Padre(esto se convierte en programacion en capas)
class Persona:
    def __init__(self, clv, nom, ed):
        self.clave = clv
        self.nombre = nom
        self.edad = ed
    def mostrarDatos(self,):
        print("Mostrando los Datos desde la SuperClase")
        print("CLAVE: ", self.clave)
        print("NOMBRE: ", self.nombre)
        print("EDAD: ", self.edad)

#CON ESTO CREAMOS LA HERENCIA
class Trabajador(Persona):
    def __init__(self, clv, nom, ed, suel):
        self.clave = clv
        self.nombre = nom
        self.edad = ed
        self.sueldo = suel
    def mostrarDatos(self,):
        print("____________________________________")
        print("Mostrando los Datos desde la SubClase")
        print("CLAVE: ", self.clave)
        print("NOMBRE: ", self.nombre)
        print("EDAD: ", self.edad)
        print("SUELDO: ", self.sueldo)
        # creando instancias (Objetos)

Administrador = Persona("AAMM45", "elias PARAMO", 35)
Empleado = Trabajador("AAMM45", "PEDRO PARAMO", 35, 2350500)
Administrador.mostrarDatos()
Empleado.mostrarDatos()
    
asked by Jsierra2017 26.05.2017 в 18:16
source

2 answers

1

Well, as I understand from your comments, something like this should work:

>>> class A():
...   def __init__(self):
...     self.x = None
...     self.y = None
...
...   def obtener_datos(self):
...     self.x = input('Valor de X: ')
...     self.y = input('Valor de Y: ')
...
...   def mostrar_datos(self):
...     print('X: ', self.x)
...     print('Y: ', self.y)
... 
>>> a = A()
>>> a.mostrar_datos()
X:  None
Y:  None
>>> a.obtener_datos()
Valor de X: Cesar
Valor de Y: 100
>>> a.mostrar_datos()
X:  Cesar
Y:  100

I just created the obtener_datos() method to use input and save it in each attribute. You just have to take it to your example.

    
answered by 26.05.2017 / 18:43
source
0

It is not clear to me why the input brings you problems. Either you use the mechanism of @Cesar or if you do not want to encapsulate the inputs in the class, you could usually do this:

clv = input("Ingrese la clave:")
nom = input("Ingrese el nombre:")
ed = input("Ingrese la edad:")
Administrador = Persona(clv, nom, ed)

clv = input("Ingrese la clave:")
nom = input("Ingrese el nombre:")
ed = input("Ingrese la edad:")
suel = input("Ingrese el sueldo:")
Empleado = Trabajador(clv , nom , ed , suel )

Administrador.mostrarDatos()
Empleado.mostrarDatos()
    
answered by 26.05.2017 в 19:02