隆Te damos la bienvenida a este reto!

1

Empezando con Python desde 0

D铆a 1

2

Variables, funciones y sintaxis b谩sica

3

Tipos de datos: Numbers, Strings y Diccionarios

4

Playground - Retorna el tipo

D铆a 2

5

Operadores

6

Playground - Calcula la propina

D铆a 3

7

Condicionales

8

Playground - Averigua si un a帽o es bisiesto

9

Ciclos

10

Playground - Dibuja un triangulo usando bucles

D铆a 4

11

Listas

12

Encuentra a los gatitos m谩s famosos

13

Diccionarios

14

Obt茅n el promedio de los estudiantes

15

Tuplas

16

Obten la informaci贸n de los paquetes

D铆a 5

17

Calcula la cantidad de letras en una oraci贸n

18

Encuentra el mayor pal铆ndromo

D铆a 6

19

Sets

20

Encuentre la intersecci贸n de conjuntos

D铆a 7

21

List comprehension

22

Encuentra palabras con dos vocales

23

Dictionary Comprehension

24

Calcula la longitud de las palabras

D铆a 8

25

Funciones Lambda

26

Filtra mensajes de un user espec铆fico

27

Higher order functions

28

Crea tu propio m茅todo map

D铆a 9

29

Manejo de Errores y excepciones

30

Maneja correctamente los errores

31

Maneja las excepciones

D铆a 10

32

Playground - Crea un task manager usando closures

D铆a 11

33

Lectura de archivos de texto y CSV

D铆a 12

34

Programaci贸n orientada a objetos

35

Crea un auto usando clases

D铆a 13

36

Abstracci贸n en Python

37

Playground - Crea un sistema de carrito de compras

38

Encapsulamiento en Python

39

Playground - Encapsula datos de los usuarios

D铆a 14

40

Herencia en Python

41

Playground - Jerarqu铆a de animales usando herencia

D铆a 15

42

Polimorfismo en Python

43

Playground - Implementa un sistema de pagos

D铆a 16

44

Estructuras de datos en Python

45

Playground - Crea tu propia lista en python

46

Hash tables en Python

47

Playground - Implementaci贸n de una HashTable para Contactos

D铆a 17

48

Maps en Python

49

Playground - Crea un task manager con Maps

D铆a 18

50

Singly Linked List en Python

51

Playground - Implementaci贸n de una singly linked list

D铆a 19

52

Stacks en Python

53

Playground - Implementaci贸n de un stack

D铆a 20

54

Queues en Python

55

Playground - Implementaci贸n de una queue

D铆a 21

56

隆Lo lograste!

No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

脷ltima oportunidad para asegurar tu aprendizaje por 1 a帽o a precio especial

Antes: $249

Currency
$189/a帽o

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscr铆bete

Termina en:

1D
8H
51M
25S

Crea un auto usando clases

35/56

Aportes 31

Preguntas 0

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

No me la puedo creerrrr tiooo, que hace unos d铆as andaba chillando y que ahorita hice esto super f谩cil, hay que darle cr茅dito al video de soy Dalto:

youtube_com/watch?v=HtKqSJX7VoM&list=LL&index=3

class Carro:
  def __init__(self, marca, modelo, ano, kilometraje):
    self.marca = marca
    self.modelo = modelo
    self.ano = ano
    self.kilometraje = kilometraje
    self.estado = False

  def turnOn(self):
    self.estado = True

  def turnOff(self):
    self.estado = False

  def drive(self, kms):
    if(self.estado):
      self.kilometraje += kms
    else:
      raise Exception("El auto esta apagado")    

toyota = Carro("Toyota", "Corolla", 2020, 34)

print(toyota.marca) # Toyota
print(toyota.modelo) # Corolla
print(toyota.ano) # 2020
print(toyota.kilometraje) # 34
print(toyota.estado) # False


.
.
.
.
.

Con base a los apuntes de la clase y a los ejemplos de mis compa帽eros, comprendi realzar este ejercicio. Muchas gracias a todos

class Vehiculo:

Atributos. Especificaciones del Veh铆culo

def init(self, Marca, Modelo, A帽o, Kilometraje):
self.Marca = Marca # Marca del Veh铆vulo
self.Modelo = Modelo # Modelo del Veh铆vulo
self.A帽o = A帽o # A帽o del Veh铆vulo
self.Kilometraje = Kilometraje # Kilometraje del Veh铆vulo
self.Estado = False # Estado del Veh铆vulo (Apagado)

M茅todo. Funcionamiento del veh铆culo

def turnOn(self):
self.Estado = True # Estado Encendido
def turnOff(self):
self.Estado = False # Estado Apagado
def drive(self, Kilometraje):
if self.Estado != True: # Aumenta el Kilometraje
raise Exception(鈥淓l veh铆culo se encuentra apagado鈥)
self.Kilometraje += Kilometraje

class Car:
    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model = model
        self.year = year
        self.mileage = mileage
        self.state = False

    def turnOn(self):
        self.state = True
    
    def turnOff(self):
        self.state = False

    def drive(self, kilometers):
        if self.state:
            self.mileage += kilometers
        else:
            raise Exception("El auto est谩 apagado")
aqui mi aporte: ![](https://static.platzi.com/media/user_upload/image-8a1811fe-0220-4712-8e85-3118a442af21.jpg)

Mi c贸digo, agregu茅 una expeci贸n extra en caso que el kilometraje no sea num茅rico
.
.
.
.
.
.
.
.
.
.

<code> 
class Car:
    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model = model
        self.year = year
        self.mileage = mileage
        self.state = False
    
    def turnOn(self):
        self.state = True
    
    def turnOff(self):
        self.state = False

    def drive(self, kilometer):
       try:
        if kilometer > 0:
         if not self.state:
           raise ValueError("Exception: El auto est谩 apagado")   
        self.mileage += kilometer
       except TypeError as e:
            print("TypeError:", e)

Mi ejercicio:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    # Tu c贸digo aqu铆 馃憟
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True
      
  def turnOff(self):
    self.state = False

  def drive(self, kilometers):
    if self.state:
      self.mileage += kilometers
    else:
      raise Exception('El auto est谩 apagado')

    pass


.
.
.
Listo! 馃悕馃憣馃徏
.
.
.
.
.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self, kilometers):
    if(self.state):
      self.mileage += kilometers
    else:
      raise Exception("El auto est谩 apagado")  

馃洝锔忦煕★笍Escudo anti-spoilers馃洝锔忦煕★笍

Mi soluci贸n al reto:

class Car:
  def __init__(self, brand, model, year, mileage):
    self.state = False
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage 

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self,kilometers):
    if self.state:
      self.mileage += kilometers
    else:
      raise Exception("El auto est谩 apagado") 

Comparto mi reto:

.
.

class Car:
    state = False

    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model =model
        self.year = year
        self.mileage = mileage

    def turnOn(self):
        self.state = True

    def turnOff(self):
        self.state = False

    def drive(self, kilometers):
        if self.state == True:
            self.mileage += kilometers
            return self.mileage
        else:
            raise Exception('El auto est谩 apagado')


.
.
.
.
.
.
.
.
.
.

Mi soluci贸n:

class Car:
    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model = model
        self.year = year
        self.mileage = mileage
        self.state = False

    def turnOn(self):
        self.state = True

    def turnOff(self):
        self.state = False

    def drive(self, kilometers):
        if not self.state:
            raise Exception("El auto est谩 apagado")
        self.mileage += kilometers

Soluci贸n 馃槃鈥
.

.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False
  
  def drive(self, kilometers):
    if self.state:
      self.mileage += kilometers
    else:
      raise Exception("El auto est谩 apagado")

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self, kilometers):
    if self.state != True:
      raise Exception("El auto est谩 apagado")
    self.mileage += kilometers
class Car:
    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model = model 
        self.year = year 
        self.mileage = mileage
        self.state = False


    def turnOn(self):
        self.state = True
    def turnOff(self):
        self.state = False
    def drive(self,km):
        if (self.state):
            self.mileage = self.mileage + km 
        else:
            raise Exception("El auto est谩 apagado")
            
            
    



toyota = Car("Toyota", "Corolla", 2020, 0)
toyota.drive(200)
print(toyota.mileage)




.
.
.
.
.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
      
  def turnOn(self):
     self.state = True
  
  def turnOff(self):
     self.state = False
  
  def drive(self, kilometers):
     if self.state:
        self.mileage += kilometers
     else:
        raise Exception('El auto est谩 apagado')
     
toyota = Car("Toyota", "Corolla", 2020, 0)
toyota.turnOn()
toyota.drive(100)
print(toyota.mileage)

toyota = Car("Toyota", "Corolla", 2020, 0)
toyota.turnOff()
toyota.drive(100)
print(toyota.mileage)

Aqu铆 mi soluci贸n, pero no pas贸 las pruebas, a seguir estudiando

Cada vez est谩n m谩s espectaculares los retos.

class Car:
  def __init__(self,brand,model,year,mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
  
  def turnOn(self):
    self.state=True

  def turnOff(self):
    self.state=False

  def drive(self,kilometers):
    if self.state == True:
      self.mileage += kilometers
    else:
      raise Exception("El auto est谩 apagado")

toyota = Car("Toyota", "Corolla", 2020, 0);


Dejo mi solucion!

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self, kilometers):
    if self.state == False:
      raise Exception('El auto est谩 apagado')
    self.mileage += kilometers

Dejo mi respuesta de modelado de clase. Lo 煤nico que me causo ruido es lo de pasar self siempre en los m茅todos.

class Car:
  state = False
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    pass

  def turnOn(self):
    self.state = True
    pass

  def turnOff(self):
    self.state = False
    pass

  def drive(self,kilometers):
    if not self.state:
      raise Exception('El auto est谩 apagado')
    else:
      self.mileage = kilometers
    pass
class Car:

  state: bool = False

  def __init__(self, brand, model, year, mileage):
    self.brand: str = brand
    self.model: str = model
    self.year: int = year
    self.mileage: int = mileage

  def turnOn(self):
    self.state = True
  
  def turnOff(self):
    self.state = False
  
  def drive(self, kilometers):
    if self.state == False:
      raise Exception("El auto est谩 apagado") 
    else:  
      self.mileage += kilometers

Aqui mi codigo:
.
.
.
.
.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    # Tu c贸digo aqu铆 馃憟
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self, kilometers):
    if self.state == True:
      self.mileage += kilometers
    else:
      raise Exception("El auto est谩 apagado")
Se han recorrido 150 kil贸metros. Kilometraje actual: 10150 km.

Se han recorrido 50 kil贸metros. Kilometraje actual: 10200 km.

El auto est谩 apagado.

El auto est谩 apagado.

Buena pr谩ctica, solo que no me gusta manejar el traceback en la exception, pero lo obliga.


o
o
o
o

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand   = brand
    self.model   = model
    self.year    = year
    self.mileage = mileage
    self.state   = False 

  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state = False

  def drive(self, miles):
    if self.state:
      self.mileage += miles
    else:
      raise Exception ("El auto est谩 apagado")
     
  
toyota = Car("Toyota", "Corolla", 2020, 0)
toyota.turnOn();
toyota.drive(100);
toyota.mileage

toyota = Car("Toyota", "Corolla", 2020, 0)
toyota.turnOff()
toyota.drive(100)


*
*
*
*
*

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
  
  def turnOn(self):
    self.state = True
  
  def turnOff(self):
    self.state = False

  def drive(self, killometers):
    if self.state:
      self.mileage += killometers
    else:
      raise Exception("El auto est谩 apagado")

Mi soluci贸n:
+
+
+
+
+
+
+
+
+
+
+
+
+
+

class Car:
  def __init__(self, brand, model, year, mileage):
    # Tu c贸digo aqu铆 馃憟
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
  
  def turnOn(self):
    self.state = True

  def turnOff(self):
    self.state =False
  
  def drive(self, kilometers):
      if self.state:
        self.mileage += kilometers
      else:
        raise Exception("El auto est谩 apagado") 


.
.
.

class Car:
  def __init__(self, brand, model, year, mileage=0):

    self.brand=brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
  def turnOn(self):
    self.state=True
  def turnOff(self):
    self.state = False
  def drive(self,kilometers):
    if self.state:
      self.mileage=self.mileage+kilometers
    else: 
       raise Exception("El auto est谩 apagado")
class Car:
  def __init__(self, brand, model, year, mileage=0,state=False):
    self.brand=brand
    self.model=model
    self.year=year
    self.mileage=mileage
    self.state=state

  def turnOn(self): #M茅todo que encender谩 el auto.
    self.state=True
  def turnOff(self): #M茅todo que apagar谩 el auto.
    self.state=False
  def drive(self,kilometers):  #Con este m茅todo podremos 
    assert self.state=True,"El auto est谩 apagado"
    self.mileage=self.mileage+kilometers


.
.
.
.
.

class Car:
  def __init__(self, brand, model, year, mileage):
    self.brand = brand
    self.model = model
    self.year = year
    self.mileage = mileage
    self.state = False
  
  def turnOn(self):
    self.state = True
  
  def turnOff(self):
    self.state = False
  
  def drive(self, kilometers):
    if self.state == False:
      raise Exception("El auto est谩 apagado")
    self.mileage += kilometers

class Car:
    def __init__(self, brand, model, year, mileage):
        self.brand = brand
        self.model = model
        self.year = year
        self.mileage = mileage
        self.state = False

    def turnOn(self):
        self.state = True

    def turnOff(self):
        self.state = False

    def drive(self, kilometers):
        if self.state:
            self.mileage += kilometers
        else:
            raise Exception("El auto est谩 apagado")
undefined