Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- #
- '''
- def ingresar_entero():
- while True:
- try:
- numero = int(input("Ingrese un numero entero: "))
- except ValueError:
- print("No ha ingresado un nro entero")
- else:
- return numero
- numero = ingresar_entero()
- if numero:
- print(f"El cociente entre 5 y {numero} es {5/numero}")
- else:
- print("No se puede dividir por cero")
- """
- try:
- print(f"El cociente entre 5 y {numero} es {5/numero}")
- except ZeroDivisionError:
- print("No se puede dividir por cero")
- """
- '''
- # LANZAMIENTO DE EXCEPCIONES
- def sumar(a,b):
- """Función que suma dos numeros"""
- if not isinstance(a,(int,float)) or not isinstance(b,(int,float)):
- raise TypeError("Se necesitan dos nros")
- return a + b
- #print(sumar("Hola","Chau"))
- print(sumar(2,3))
- """
- #simulacion de conexion a internet
- try:
- # conexion a internet
- except (Error1, Error2):
- # print("Error de conexión")
- else:
- # hago mi codigo
- finally: --> se ejecuta siempre, haya o no excepcion
- # cerrar la conexion
- """
Advertisement
Add Comment
Please, Sign In to add comment