Home Foros Foro dudas Foro Python Ejercicio Python Tutorizado , POO Respuesta a: Ejercicio Python Tutorizado , POO

Respuesta a: Ejercicio Python Tutorizado , POO

Home Foros Foro dudas Foro Python Ejercicio Python Tutorizado , POO Respuesta a: Ejercicio Python Tutorizado , POO

#15702
<span style="color: #cc7832;">class </span>Vehiculo:
    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas):
        <span style="color: #94558d;">self</span>.marca = marca
        <span style="color: #94558d;">self</span>.modelo = modelo
        <span style="color: #94558d;">self</span>.color = color
        <span style="color: #94558d;">self</span>.ruedas = ruedas
        <span style="color: #94558d;">self</span>.marchas = marchas
        <span style="color: #94558d;">self</span>.acelera = <span style="color: #cc7832;">False
</span>        <span style="color: #94558d;">self</span>.frena = <span style="color: #cc7832;">False
</span>        <span style="color: #94558d;">self</span>.arranque = <span style="color: #cc7832;">False
</span>
<span style="color: #cc7832;">    def </span><span style="color: #ffc66d;">datos_Veh</span>(<span style="color: #94558d;">self</span>):
        <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Datos del vehículo: " </span>+ <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Marca: " </span>+ <span style="color: #94558d;">self</span>.marca + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Modelo: " </span>+ <span style="color: #94558d;">self</span>.modelo + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Color: " </span>+ <span style="color: #94558d;">self</span>.color + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Número de ruedas: " </span>+ <span style="color: #8888c6;">str</span>(
            <span style="color: #94558d;">self</span>.ruedas)

    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">arrancar</span>(<span style="color: #94558d;">self</span>):
        <span style="color: #94558d;">self</span>.arranque = <span style="color: #cc7832;">True
</span><span style="color: #cc7832;">        if </span><span style="color: #94558d;">self</span>.arranque:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Hemos arrancado"
</span>
    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">acelerar</span>(<span style="color: #94558d;">self</span>):
        <span style="color: #94558d;">self</span>.acelera = <span style="color: #cc7832;">True
</span>
<span style="color: #cc7832;">    def </span><span style="color: #ffc66d;">frenar</span>(<span style="color: #94558d;">self</span>):
        <span style="color: #94558d;">self</span>.frena = <span style="color: #cc7832;">True
</span>

<span style="color: #cc7832;">class </span>Coche(Vehiculo):

    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ancho<span style="color: #cc7832;">, </span>alto<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas<span style="color: #cc7832;">, </span>n_plazas<span style="color: #cc7832;">, </span>aire<span style="color: #cc7832;">, </span>derrapar):
        Vehiculo.<span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas)
        <span style="color: #94558d;">self</span>.n_marchas = marchas
        <span style="color: #94558d;">self</span>.n_plazas = n_plazas
        <span style="color: #94558d;">self</span>.alto = alto
        <span style="color: #94558d;">self</span>.ancho = ancho
        <span style="color: #94558d;">self</span>.aire = aire
        <span style="color: #94558d;">self</span>.derrapar = derrapar

    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">datos_Veh</span>(<span style="color: #94558d;">self</span>):
        <span style="color: #cc7832;">return </span><span style="color: #8888c6;">super</span>().datos_Veh() + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Ancho del vehículo: " </span>+ <span style="color: #8888c6;">str</span>(
            <span style="color: #94558d;">self</span>.ancho) + <span style="color: #6a8759;">" mm." </span>+ <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Alto del vehículo: " </span>+ <span style="color: #8888c6;">str</span>(<span style="color: #94558d;">self</span>.alto) + <span style="color: #6a8759;">" mm." </span>+ \
               <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">El vehículo tiene: " </span>+ <span style="color: #8888c6;">str</span>(<span style="color: #94558d;">self</span>.n_marchas) + <span style="color: #6a8759;">" Velocidades" </span>+ <span style="color: #6a8759;">" Y " </span>+ \
               <span style="color: #8888c6;">str</span>(<span style="color: #94558d;">self</span>.n_plazas) + <span style="color: #6a8759;">" plazas."
</span>
    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">aire_Ac</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">if </span><span style="color: #94558d;">self</span>.aire:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"El vehículo tiene aire acondicionado"
</span>
        <span style="color: #cc7832;">else</span>:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"El vehículo no tiene aire acondicionado"
</span>
    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">derrape</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">if </span><span style="color: #94558d;">self</span>.derrapar:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Vamos de lado y sin manos......"
</span>
        <span style="color: #cc7832;">else</span>:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Acelera coño...."
</span>
    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">ir_Marcha_atras</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Vamos marcha atrás."
</span>

<span style="color: #cc7832;">class </span>Furgoneta(Coche):

    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ancho<span style="color: #cc7832;">, </span>alto<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas<span style="color: #cc7832;">, </span>n_plazas<span style="color: #cc7832;">, </span>aire<span style="color: #cc7832;">, </span>derrapar<span style="color: #cc7832;">, </span>carga):
        Coche.<span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ancho<span style="color: #cc7832;">, </span>alto<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas<span style="color: #cc7832;">, </span>n_plazas<span style="color: #cc7832;">, </span>aire<span style="color: #cc7832;">, </span>derrapar)
        <span style="color: #94558d;">self</span>.carga = carga

    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">cargando</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">if </span><span style="color: #94558d;">self</span>.carga:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">La furgoneta está cargada."
</span>        <span style="color: #cc7832;">else</span>:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">La furgoneta no está cargada."
</span>

<span style="color: #cc7832;">class </span>Bicicleta:
    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span><span style="color: #72737a;">marca</span><span style="color: #cc7832;">, </span><span style="color: #72737a;">modelo</span><span style="color: #cc7832;">, </span><span style="color: #72737a;">color</span><span style="color: #cc7832;">, </span><span style="color: #72737a;">ruedas</span><span style="color: #cc7832;">, </span><span style="color: #72737a;">marchas</span><span style="color: #cc7832;">, </span>caballito):
        <span style="color: #94558d;">self</span>.caballito = caballito

    <span style="color: #cc7832;">def </span><span style="color: #ffc66d;">h_caballito</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">if </span><span style="color: #94558d;">self</span>.caballito:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Voy haciendo un caballito"
</span>
        <span style="color: #cc7832;">else</span>:
            <span style="color: #cc7832;">return </span><span style="color: #6a8759;">"Las dos ruedas en el suelo"
</span>

<span style="color: #cc7832;">class </span>Moto(Vehiculo<span style="color: #cc7832;">, </span>Bicicleta):
    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas<span style="color: #cc7832;">, </span>caballito<span style="color: #cc7832;">, </span>q_rueda):
        Vehiculo.<span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas)
        Bicicleta.<span style="color: #b200b2;">__init__</span>(<span style="color: #94558d;">self</span><span style="color: #cc7832;">, </span>marca<span style="color: #cc7832;">, </span>modelo<span style="color: #cc7832;">, </span>color<span style="color: #cc7832;">, </span>ruedas<span style="color: #cc7832;">, </span>marchas<span style="color: #cc7832;">, </span>caballito)
        <span style="color: #94558d;">self</span>.q_rueda = q_rueda

    <span style="color: #cc7832;">def </span><span style="color: #b200b2;">__str__</span>(<span style="color: #94558d;">self</span>):

        <span style="color: #cc7832;">if </span><span style="color: #94558d;">self</span>.q_rueda:
            <span style="color: #cc7832;">return </span><span style="color: #8888c6;">super</span>().datos_Veh + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Y estoy quemando una como si me las regalasen."
</span>        <span style="color: #cc7832;">else</span>:
            <span style="color: #cc7832;">return </span><span style="color: #8888c6;">super</span>().datos_Veh + <span style="color: #6a8759;">"</span><span style="color: #cc7832;">\n</span><span style="color: #6a8759;">Y no las estoy quemando, porque las ruedas son caras."
</span>

<span style="color: #808080;"># V1 = Coche("Opel", "Vectra", "Rojo", 2500, 1500, 4, 5, 5, False, False, )
</span><span style="color: #808080;"># print(V1.datos_Veh())
</span><span style="color: #808080;"># print(V1.arrancar())
</span><span style="color: #808080;"># print(V1.aire_Ac())
</span><span style="color: #808080;"># print(V1.ir_Marcha_atras())
</span><span style="color: #808080;"># V2=Furgoneta("Mercedes", "Viano", "Blanco",2350,1890,4,6,7,True, False,True)
</span><span style="color: #808080;"># print(V2.datos_Veh())
</span><span style="color: #808080;"># print(V2.Cargando())
</span><span style="color: #808080;"># print(V2.aire_Ac())
</span><span style="color: #808080;"># V3 = Moto ("Suzuki", "Katana", "Azul/blanca", 2, 1, False, False)
</span><span style="color: #808080;"># print(V3.datos_Veh())
</span><span style="color: #808080;"># V4 = Bicicleta("Orbea", "GR6000", "Roja", 2, 18, False)
</span><span style="color: #808080;"># print(V4.h_caballito())</span>