Python Projects

Calculator With Python

PREREQUISITES

To Practice this Program, you should have a basic knowledge of the following Topics:

PYTHON-FUNCTIONSS

INPUT & PRINT FUNCTION

We will use Input & Print Function to collect & print data from the website user into variables.

dt

INTEGER & FLOAT

We will accept the user input in float or integer so that it can be calculated.

python-py

CONDITIONALS - IF ELIF ELSE

We will use If-Elif-Else to implement the calculations as per user asked condition.

WHAT TO DO ?

Ask a website user for two numbers and desired calculation user wants to perform between them.
Calculate both the numbers.

HOW TO DO ?

Following are the steps to do :

01.

ASK NUMBERS & CALCULATION

At First, We will ask for two numbers & desired calculation user wishes to perform between two numbers.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>num1 = float(input("Enter the first number "))
num2 = float(input("Enter the second number "))
calculate = input("What calculation do you want to perform ? +, -, /, x ")
</pre>
</div>
02.

CREATING IF-ELIF-ELSE CONDITIONS

Finally, We will create IF-ELIF-ELSE Conditions as per the user’s desired calculation between two numbers.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>if calculate == "+":
  print(num1 + num2)

elif calculate == "-":
  print(num1-num2)

elif calculate == "/":
  print(num1/num2)

elif calculate == "x":
  print(num1*num2)</pre>
</div>
Things We Covered
  • Accepting User Data (Input Function with Float)
  • Creating IF-ELIF-ELSE (Conditionals)
  • Print/Output the Data (Print Function)

Posted by Akshay Gupta

Leave a Reply

Your email address will not be published. Required fields are marked *