Answers for "calculator using function in python"

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

calculator with python

#Simple python Calculator
#Enter the first variable
#then the operator
#and finally the second variable, then the answer is printed.
A = int(input("Enter your first number: "))
operator = input("Which operation would you like to perform? (+, -, /, *, //, **): ");
B = int(input("Enter your second number: "))
#Addition
if operator == "+":
    ans = A + B
    print(str(ans))
#Subraction
elif operator == "-":
    ans = A - B
    print(str(ans))
#division
elif operator == "/":
    ans = A / B
    print(str(ans))
#Multiplication
elif operator == "*":
    ans = A * B
    print(str(ans))
#Integer division
elif operator == "//":
    ans = A // B
    print(str(ans))
#Exponent
elif operator == "**":
    ans = A ** B
    print(str(ans))
else:
    print("wrong operator!")
Posted by: Guest on April-21-2021
0

python calculator

# simple calculator
try:
  # prompt user
    num1 = float(input("Please Enter The first number: "))
    operator = input("Please choose the operator (+) for addition, (-) for subtraction, (*) for multiplication"
                     "(/) for division , (%) for remainder: ")
    num2 = float(input("Please Enter The second number: "))
    
    if operator == '+':
        result = num1 + num2
        print("The result is: ", result)
    elif operator == '-':
        result = num1 - num2
        print("The result is: ", result)
    elif operator == '*':
        result = num1 * num2
        print("The result is: ", result)
    elif operator == '/':
        try:
            if True:
                result = num1 / num2
                print(result)
        except ZeroDivisionError as err:
            print(err, " oops! zero division occur ")
    elif operator == '%':
        if operator == '%':
            result = num1 % num2
            print("The result is: ", result)
    else:
        raise TypeError


except ValueError:
    print("wrong value, suggest integer or decimal")
finally:
    print("All Done")
Posted by: Guest on September-23-2020

Code answers related to "calculator using function in python"

Python Answers by Framework

Browse Popular Code Answers by Language