Skip to content

Commit

Permalink
nuevos cambios
Browse files Browse the repository at this point in the history
  • Loading branch information
indadominguez committed Oct 10, 2024
1 parent e4b8853 commit 4e8e029
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ej02.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

total = str(trabajo * coste)

print("Importe Total " + (total) + "")
print("Importe Total ", total)

#Es otra manera, la dejo para tener más opciones de solución

Expand Down
2 changes: 1 addition & 1 deletion src/ej07.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

suma = num1 + num2 + num3

print("La suma de los 3 números es: ", suma)
print(f"La suma de los 3 números es: {suma:.2f}")

52 changes: 52 additions & 0 deletions src/ej_calcular_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import math

def calcular_area(a:float, b:float, c:float) -> float:
s = (a + b + c)/2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
return area


def comprobar_float(valor: str) -> bool:
if valor.startswith("-"): #-88.67
valor = valor[1:] #88.67

pos_punto = valor.find(".") #2
if pos_punto >= 0:
valor = valor[:pos_punto] + valor[pos_punto + 1:] #8867

return valor.isdigit()


def introduce_numero(msj: str) -> float:
valor = input(msj).strip().replace(",", ".")

while not comprobar_float(valor):
print("\n**ERROR** Número inválido!")
valor = input(msj).strip().replace(",", ".")

return float(valor)


def comprobar_triangulo_valido(a, b, c):
return (a + b >c) and(a + c >b) and (b + c > a)


def main():
print("Dame los tres lados del triángulo...")

lado_a = introduce_numero("Lado 1: ")
lado_b = introduce_numero("Lado 2: ")
lado_c = introduce_numero("Lado 3: ")

if comprobar_triangulo_valido(lado_a, lado_b, lado_c):
area = calcular_area(lado_a, lado_b, lado_c)
print("El area del triangulo con lados ({:.2f}, {:.2f}, {:.2f}) es {:.2f}.".format (lado_a, lado_b, lado_c, area))
else:
print("El area del triangulo con lados ({:.2f}, {:.2f}, {:.2f}) no es valido.".format (lado_a, lado_b, lado_c))





if __name__ == "__main__":
main()

0 comments on commit 4e8e029

Please sign in to comment.