Skip to content

KrzysztofDzioba/Simple-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

import operator import sys

ops = {"+": operator.add, "-": operator.sub, '*': operator.mul, '/': operator.truediv, }

def calculation():

while True:
    calculation_input = input('Enter an operation: ')

    if calculation_input == '+' or calculation_input == '-' or calculation_input == '*' or calculation_input == '/':
        return cal(calculation_input)
        break

def isint(value): try: int(value) return True except: return False

def cal(calculation):

while True:

    number_2 = input('Enter another number: ')
    if isint(number_2):
        number_2 = int(number_2)
        result = ops[calculation](number_1, number_2)
        print('Result:', result)
        print(' ')
        calculation1()
    else:
        print ("This is not a number.")
        cal(calculation)
        break

def calculation1(): while True: number_1 = input('Enter number (or a letter to exit): ') if isint(number_1): number_1 = int(number_1) calculation() else: sys.exit(0)

while True: number_1 = input('Enter number (or a letter to exit): ') if isint(number_1): number_1 = int(number_1) calculation() else: break

About

Simple calculator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published