Answers for "what is phython calculator"

1

basic calculator in python

#My Personal Python calculator
print("My Personal Python calculator")
#inputs
num1 = int(input('Enter the first number:  '))
num2 = int(input('Enter the second number:  '))
#opration req
opr = input('Enter the type of operation you want to perform between your chosen two numbers:  ')
#calculation
if opr=='+':
    ans = num1 + num2
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr == '- ':
    ans = num1 - num2
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr=='*':
    ans = num1 * num2;
    # displaying the answer
    print(f'Your final answer is {ans}')
elif opr=='/':
    ans = num1 / num2
    # displaying the answer
    print(f'Your final answer is {ans}')
else:
    print('Invalid Entry!!!')
Posted by: Guest on December-25-2020
0

python calculator

import time
def cal():
    def add(x, y):
        print(x + y)

    def sub(x, y):
        print(x - y)

    def mul(x, y):
        print(x * y)

    def div(x, y):
        print(x // y)

    while True:
        print('Adding?(+) Subtracting?(-) Multiplying?(*) Dividing?(/)')
        answer = input('')
        if answer == "+":
            try:
                x = float(input('First number! '))
                y = float(input('Second Number! '))
            except Exception as e:
                print(f'Error: {e}')
                time.sleep(5)
                return
            add(x, y)
        elif answer == "-":
            try:
                x = float(input('First number! '))
                y = float(input('Second Number! '))
            except Exception as e:
                print(f'Error: {e}')
                time.sleep(5)
                return
            sub(x, y)
        elif answer == "*":
            try:
                x = float(input('First number! '))
                y = float(input('Second Number! '))
            except Exception as e:
                print(f'Error: {e}')
                time.sleep(5)
                return
            mul(x, y)
        elif answer == "/":
            try:
                x = float(input('First number! '))
                y = float(input('Second Number! '))
            except Exception as e:
                print(f'Error: {e}')
                time.sleep(5)
                return
            div(x, y)
        else:
            print('Error. Enter a valid input!')


cal()
Posted by: Guest on March-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language