Advertisement
teslariu

funcions

Jun 3rd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """Programa que calcula perímetros y áreas de superficies en diversas
  5. figuras geométricas"""
  6.  
  7.  
  8. def calcular_circulo(radio):
  9.     import math
  10.     return [2*math.pi*radio, math.pi*radio**2]
  11.    
  12. def calcular_cuadrado(lado):
  13.     return [4*lado, lado**2]
  14.    
  15. def calcular_rectangulo(a,b):
  16.     return [2*(a+b), a*b]
  17.    
  18. def imprimir(datos):
  19.     print("Perímetro: {:.3f}  Superficie: {:.3f}".format(datos[0],datos[1]))
  20.  
  21.  
  22.  
  23.  
  24. print("""
  25. Programa que calcula perímetros y áreas de superficies en diversas
  26. figuras geométricas
  27. """)
  28.  
  29. while True:
  30.     print("""
  31.    Menu de opciones:
  32.    -----------------
  33.    1. Cuadrado
  34.    2. Rectangulo
  35.    3. Círculo
  36.    4. Salir
  37.    """)
  38.    
  39.     opcion = input("Seleccione una opción: ")
  40.    
  41.     if opcion == "1":
  42.         lado = float(input("Ingrese el lado: "))
  43.         datos = calcular_cuadrado(lado)
  44.         imprimir(datos)
  45.        
  46.     elif opcion == "2":
  47.         a = float(input("Ingrese un lado: "))
  48.         b = float(input("Ingrese el otro lado: "))
  49.         datos = calcular_rectangulo(a,b)
  50.         imprimir(datos)
  51.        
  52.        
  53.     elif opcion == "3":
  54.         radio = float(input("Ingrese el radio: "))
  55.         datos = calcular_circulo(radio)
  56.         imprimir(datos)
  57.        
  58.     elif opcion == "4":
  59.         print("Gracias por utilizar este programa...")
  60.         break
  61.        
  62.     else:
  63.         print("Opción incorrecta...")
  64.  
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement