Advertisement
teslariu

funciones ejercicio

Sep 5th, 2023
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # hacer una funcion que reciba el lado de un cuadrado y devuelva
  5. # la superficie
  6.  
  7. def ingresar_lado():
  8.     while True:
  9.         lado = input("Ingrese el lado: ")
  10.         if lado.isdecimal() and int(lado):
  11.             return int(lado)
  12.         else:
  13.             print("Error: ingrese una longitud de lado válida")
  14.  
  15. def superficie(lado):
  16.     return lado**2
  17.    
  18. def imprimir(area):
  19.     print(f"El área es {area:.2f}")
  20.    
  21.    
  22. lado = ingresar_lado()
  23. area = superficie(lado)
  24. imprimir(area)
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement