Advertisement
Guest User

Untitled

a guest
Aug 1st, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from math import sqrt
  4.  
  5. import numpy
  6.  
  7. try:
  8.     input = raw_input
  9. except NameError:
  10.     pass
  11.  
  12.  
  13. def get_numeric_value(prompt):
  14.     """
  15.    Requests a numeric value from the standard input.
  16.    Returns None if no value was inserted.
  17.    """
  18.     while True:
  19.         value = input(prompt)
  20.         if not value:
  21.             return None
  22.         try:
  23.             value = int(value)
  24.         except ValueError:
  25.             print("Debe ingresar un valor numerico. "
  26.                   "Vuelva a intentarlo.")
  27.         else:
  28.             break
  29.     return value
  30.  
  31.  
  32. def get_triangle(a=None, b=None, h=None):
  33.     """
  34.    Returns a triangle string, with the specified values.
  35.    """
  36.     return r"""
  37.    |\
  38.    | \
  39.    |  \ h
  40.  a |   \
  41.    |    \
  42.    |_ _ _\
  43.      b
  44.  
  45.    a = %s
  46.    b = %s
  47.    h = %s""" % ("?" if a is None else a,
  48.                  "?" if b is None else b,
  49.                  "?" if h is None else h)
  50.  
  51.  
  52. def main():
  53.     print(get_triangle())
  54.     print("\nDeje en blanco el valor que desconoce.\n")
  55.  
  56.     a = get_numeric_value("a: ")
  57.     b = get_numeric_value("b: ")
  58.  
  59.     if a is None or b is None:
  60.         h = get_numeric_value("h: ")
  61.     else:
  62.         h = None
  63.  
  64.     if (bool(a) + bool(b) + bool(h)) < 2:
  65.         print("Debe especificar, al menos, dos valores.")
  66.         return 0
  67.  
  68.     if h is None:
  69.         h = sqrt(a ** 2 + b ** 2)
  70.     elif a is None:
  71.         a = sqrt(h ** 2 - b ** 2)
  72.     elif b is None:
  73.         b = sqrt(h ** 2 - a ** 2)
  74.  
  75.     anguloMenor = numpy.arccos(((h * h) + (a * a) - (b * b)) / (2 * h * a))
  76.     final = numpy.rad2deg(anguloMenor)
  77.     anguloMayor = 90 - final
  78.  
  79.     print("")
  80.     print(get_triangle(a, b, h))
  81.  
  82.     print('el angulo menor de su triangulo rectangulo es: ', (final), '°')
  83.     print('el angulo mayor de su triangulo rectangulo es: ', anguloMayor, '°')
  84.  
  85.     return 0
  86.  
  87.  
  88. if __name__ == '__main__':
  89.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement