Advertisement
teslariu

e

Jul 17th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. def ingresar_numero():
  5.     while True:
  6.         try:
  7.             numero = float(input("Ingrese un número: "))
  8.         except ValueError:
  9.             print("Error: debe ingresar un numero")
  10.         else:
  11.             return numero
  12.            
  13. while True:
  14.     print("""
  15.    Calculadora básica:
  16.    ------------------
  17.    1. Sumar dos números
  18.    2. Restar dos números
  19.    3. Multiplicar dos números
  20.    4. Dividir dos números
  21.    5. Salir
  22.    """)
  23.     opcion = input("Ingrese su opción: ")
  24.    
  25.        
  26.     if opcion == "1":
  27.         a = ingresar_numero()
  28.         b = ingresar_numero()
  29.         print(a + b)
  30.        
  31.     elif opcion == "2":
  32.         a = ingresar_numero()
  33.         b = ingresar_numero()
  34.         print(a - b)
  35.            
  36.     elif opcion == "3":
  37.         a = ingresar_numero()
  38.         b = ingresar_numero()
  39.         print(a * b)
  40.        
  41.     elif opcion == "4":
  42.         a = ingresar_numero()
  43.         b = ingresar_numero()
  44.         try:
  45.             print(a / b)
  46.         except ZeroDivisionError:
  47.             print("No se puede dividir por cero")
  48.        
  49.     elif opcion == "5":
  50.         print("Gracias por utilizar este programa...")
  51.         break
  52.    
  53.     else:
  54.         print("Opción incorrecta")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement