Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- def ingresar_numero():
- while True:
- try:
- numero = float(input("Ingrese un número: "))
- except ValueError:
- print("Error: debe ingresar un numero")
- else:
- return numero
- while True:
- print("""
- Calculadora básica:
- ------------------
- 1. Sumar dos números
- 2. Restar dos números
- 3. Multiplicar dos números
- 4. Dividir dos números
- 5. Salir
- """)
- opcion = input("Ingrese su opción: ")
- if opcion == "1":
- a = ingresar_numero()
- b = ingresar_numero()
- print(a + b)
- elif opcion == "2":
- a = ingresar_numero()
- b = ingresar_numero()
- print(a - b)
- elif opcion == "3":
- a = ingresar_numero()
- b = ingresar_numero()
- print(a * b)
- elif opcion == "4":
- a = ingresar_numero()
- b = ingresar_numero()
- try:
- print(a / b)
- except ZeroDivisionError:
- print("No se puede dividir por cero")
- elif opcion == "5":
- print("Gracias por utilizar este programa...")
- break
- else:
- print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement