Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Script que implementa una calculadora simple de nros naturales
- def menu():
- return """
- Menu de opciones
- ----------------
- 1) sumar
- 2) restar
- 3) multiplicar
- 4) dividir
- 5) Salir
- """
- def ingresar(num):
- while True:
- n = input(f"Ingrese un nro {num}: ")
- if n.isdecimal():
- return int(n)
- else:
- print("Error: ingrese un entero mayor o igual a cero")
- def suma(a,b):
- return f"a + b = {a+b}"
- def resta(a,b):
- return f"a - b = {a-b}"
- def division(a,b):
- return f"a / b = {a/b}"
- def multiplicacion(a,b):
- return f"a * b = {a*b}"
- print("Calculadora simple de numeros naturales")
- while True:
- print(menu())
- opcion = input("Seleccione una opción: ")
- if opcion == "1":
- a = ingresar("a")
- b = ingresar("b")
- print(suma(a,b))
- elif opcion == "2":
- a = ingresar("a")
- b = ingresar("b")
- print(resta(a,b))
- elif opcion == "3":
- a = ingresar("a")
- b = ingresar("b")
- print(multiplicacion(a,b))
- elif opcion == "4":
- a = ingresar("a")
- while True:
- b = ingresar("b")
- if not b:
- print("No se puede dividir por cero")
- else:
- break
- print(division(a,b))
- elif opcion == "5":
- print("Hasta luego...")
- break
- else:
- print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement