Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Crear una minicalculadora que pida 2 nros a y b y devuelva las 4 op
- # aritmeticas fundamentales (+,-,/,*). Tener en cuenta todos los
- # posibles errores
- def ingresar_numero(nro):
- while True:
- try:
- numero = float(input(f"Ingrese un nro {nro}: "))
- except ValueError:
- print(f"Error, debe ingresar un nro {nro}")
- else:
- return numero
- def suma(a,b):
- return a + b
- def resta(a,b):
- return a - b
- def producto(a,b):
- return a * b
- def cociente(a,b):
- if b:
- return a / b
- else:
- raise ZeroDivisionError
- while True:
- a = ingresar_numero("a")
- b = ingresar_numero("b")
- print(f"{a} + {b} = {suma(a,b)}")
- print(f"{a} - {b} = {resta(a,b)}")
- try:
- print(f"{a} / {b} = {cociente(a,b)}")
- except ZeroDivisionError:
- print(f"{a} / {b}: No se puede dividir por cero")
- print(f"{a} * {b} = {producto(a,b)}")
- opcion = input("Presione cualquier tecla ('X' para salir): ")
- if opcion.casefold() == "x":
- print("Adios..")
- break
Advertisement
Add Comment
Please, Sign In to add comment