Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Operaciones
- # Muestra una simple manera de implementar una calculadora en python.
- # Necesita mucha mejora, validaciones, etc. Pero la idea es solo mostrar la lógica.
- # Author: David Emanuel Sandoval
- def sumar():
- a = int(input("Primer numero: ")) # pasamos el valor ingresado a entero
- b = int(input("Segundo numero: "))
- resultado = a + b
- print(resultado)
- return a + b
- def restar():
- # agregar código
- print(resultado)
- return a - b
- # Menú de opciones
- def mostrar_menu():
- opciones = """
- 1) Sumar
- 2) Restar
- 3) Muliplicar
- .........etc
- 0) Salir
- """
- print(opciones)
- def preguntar_seguir():
- print("¿Desea seguir?")
- respuesta = input("Presione 's' para sí, o 'n' para no :")
- if respuesta == 's':
- return True
- elif respuesta == 'n':
- return False
- def bucle_principal():
- while True:
- mostrar_menu()
- eleccion = input("Elegir una opcion: ")
- if eleccion == '1':
- sumar()
- if preguntar_seguir() == True:
- continue
- elif preguntar_seguir() == False:
- break
- else:
- print("Opcion desconocida")
- continue # Volvemos al inicio
- elif eleccion == '2':
- restar()
- if preguntar_seguir():
- continue
- else:
- break
- elif eleccion == 'algun otro numero':
- alguna_otra_funcion()
- # preguntar
- elif eleccion == '0':
- break # salimos del bucle
- else:
- print('Opcion inválida') # Y regresa al inicio
- if __name__ == '__main__':
- bucle_principal()
Advertisement
Add Comment
Please, Sign In to add comment