Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
What's new
2
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Projects
Groups
Snippets
Sign up now
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ernesto Crespo
tutorial-poo
Commits
32a4f37d
Commit
32a4f37d
authored
Dec 19, 2016
by
Ernesto Crespo
Browse files
Creado punto2d que hereda de la clase abstracta
parent
a5e851a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
ej12_adt.py
View file @
32a4f37d
...
...
@@ -19,7 +19,7 @@ https://pythontips.com/2016/08/19/interesting-python-tutorials/
https://codequs.com/p/HJo2PAkgc/django-application-inside-a-docker-container/
https://github.com/dloss/python-pentest-tools
"""
from
math
import
sqrt
from
abc
import
ABCMeta
,
abstractmethod
class
ADTPunto
(
object
):
...
...
@@ -34,7 +34,7 @@ class ADTPunto (object):
pass
@
abstractmethod
def
mover
(
self
):
def
mover
(
self
,
puntoNuevo
):
pass
@
abstractmethod
...
...
@@ -45,9 +45,67 @@ class ADTPunto (object):
def
distanciaOtroPunto
(
self
,
punto
):
pass
class
Punto
(
ADTPunto
):
def
__init__
(
self
,
x
,
y
):
self
.
__x
=
x
self
.
__y
=
y
super
(
Punto
,
self
).
__init__
()
@
property
def
punto
(
self
):
"""el getter de punto, devuelve el punto"""
return
(
self
.
__x
,
self
.
__y
)
@
punto
.
setter
def
punto
(
self
,
Punto
):
"""Asigna nuevo valor al punto"""
self
.
__x
=
Punto
.
punto
[
0
]
self
.
__y
=
Punto
.
punto
[
1
]
@
punto
.
deleter
def
punto
(
self
):
"""Borra los valores del punto"""
del
self
.
__x
del
self
.
__y
@
property
def
ValorX
(
self
):
"""Devuelve el valor de x"""
return
self
.
__x
@
property
def
ValorY
(
self
):
"""Devuelve el valor de y"""
return
self
.
__y
def
reset
(
self
):
"""Fija el punto en (0,0)"""
self
.
__x
=
0
self
.
__y
=
0
def
distanciaOtroPunto
(
self
,
oPunto
):
'''devuelve la distancia entre el punto original y un punto dado'''
return
sqrt
((
self
.
__x
-
oPunto
.
punto
[
0
])
**
2
+
(
self
.
__y
-
oPunto
.
punto
[
1
])
**
2
)
def
mover
(
self
,
oPunto
):
"""Cambia el punto a un nuevo punto"""
self
.
__x
=
oPunto
.
punto
[
0
]
self
.
__y
=
oPunto
.
punto
[
1
]
if
__name__
==
"__main__"
:
try
:
prueba
=
ADTPunto
()
except
(
TypeError
):
print
(
"No puede instanciar un tipo abstracto de datos"
)
punto2d
=
Punto
(
3
,
5
)
print
(
punto2d
.
punto
)
print
(
punto2d
.
ValorX
)
print
(
punto2d
.
ValorY
)
punto2d
.
mover
(
Punto
(
5
,
5
))
print
(
punto2d
.
punto
)
print
(
punto2d
.
distanciaOtroPunto
(
Punto
(
10
,
10
)))
punto2d
.
reset
()
print
(
punto2d
.
punto
)
ej15.py
0 → 100644
View file @
32a4f37d
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class
Vehiculo
(
object
):
"""Clase vehiculo"""
def
__init__
(
self
,
color
,
puertas
,
cauchos
,
tipovehiculo
):
"""Constructor"""
self
.
color
=
color
self
.
puertas
=
puertas
self
.
cauchos
=
cauchos
self
.
tipovehiculo
=
tipovehiculo
def
frenar
(
self
):
"""Detener el carro """
return
"frenando"
def
manejar
(
self
):
"""manejar el carro"""
return
"Conduciendo"
class
Carro
(
Vehiculo
):
def
frenar
(
self
):
return
"Clase carro frena lentamente"
if
__name__
==
"__main__"
:
carro
=
Vehiculo
(
"Azul"
,
4
,
4
,
"carro"
)
print
(
carro
.
frenar
())
camioneta
=
Vehiculo
(
"Negra"
,
5
,
4
,
"camioneta"
)
print
(
camioneta
.
color
)
print
(
camioneta
.
puertas
)
car
=
Carro
(
"Amarillo"
,
4
,
4
,
"carro"
)
print
(
car
.
frenar
())
ej16.py
0 → 100644
View file @
32a4f37d
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Composición"""
class
A
(
object
):
def
a1
(
self
):
print
(
"a1"
)
class
B
(
object
):
def
b
(
self
):
print
(
"b"
)
A
().
a1
()
if
__name__
==
"__main__"
:
objetoB
=
B
()
objetoB
.
b
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment