Building a simple calculator

10 1 0
                                        


In this activity, you are required to build a simple calculator that can add, subtract, multiply and divide two numbers input by the user.

I will state the steps as in form of comments in python.

#Print the terms 'addition', 'subtraction', 'multiplication', and 'division'

# Then ask the user for his or her choice

#If the choice is not a value mentioned, then say "Value is not detected"

# Complete the task using if and else statements

I have mentioned the code that I have created to perform this task below.

print ("1.Addition

2.Subtraction

3.Multiplication

4.Division")choice = input ("Enter your choice : ")num1 = int(input("Enter 1st number = "))num2 = int(input("Enter 2nd number = "))if choice=='1': print("Result = ", num1+num2)if choice=='2': print("Result = ", num1-num2)if choice=='3': print("Result = ", num1*num2)if choice=='4': print("Result = ", num1//num2)else: ("Your choice cannot be detected!")


Addition:

Subtraction:

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

Subtraction:

Multiplication:

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

Multiplication:

Multiplication:

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

Division:

There are numerous other ways you could use python to build a simple calculator

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

There are numerous other ways you could use python to build a simple calculator. You could make adjustments to this code and make a more efficient code that could function with float values and other numerals, and calculate other values as well.

Python programming for BeginnersWhere stories live. Discover now