💻Project 4 : Calculator In Python

Overview

Project 4 : Calculator In Python

This Python project is a basic calculator that performs arithmetic operations on two numbers. The project employs fundamental programming concepts like functions, if-else statements, variables, and datatypes to provide a simple calculator interface.

Here's a description of the project in simple language:

  1. Introduction and Instructions: The program begins by taking input from user.

  2. Taking User Inputs: The program prompts the user to enter two numbers and the desired arithmetic operation. These inputs are stored in variables x, y, and a, respectively.

  3. Conditions and Calculations:

    • The program uses if-else statements to determine the operation to perform based on the value of a (operation keyword).
    • If the operation is +, the program adds the two numbers and prints the result.
    • If the operation is -, it subtracts the second number from the first and prints the result.
    • If the operation is , * it multiplies the two numbers and prints the result.
    • If the operation is /, it divides the first number by the second and prints the result.
    • If the operation is **, it calculates the first number raised to the power of the second number and prints the result.
  4. Invalid Input Handling: If the input for the operation is not one of the specified symbol, the program prints "Invalid Input" to indicate that the input is not recognized.

In summary, this project demonstrates a simple calculator that performs arithmetic calculations based on user inputs. The user is instructed to use specific symbol(+,_,*,/,**) for operations, and the program responds with the calculated result or an "Invalid Input" message. This project effectively utilizes programming concepts like functions for displaying instructions, if-else statements for decision-making, variables to store user inputs, and datatypes for numeric calculations.

Code

 1# Exersice 1
 2print("\nWellcome to Calculator.")
 3
 4# Input System
 5x = input("Enter First Number :- ")
 6y = input("Enter Second Number :- ")
 7a = input("Enter The Symbol Of Operation(+,-,*,/,**) :- ")
 8
 9# Calculation Processor
10if (a == "+"):
11        print("\nLet's Calculate !!!")
12        print("Addition Of",x,"and",y,"is",eval(x)+eval(y))
13
14elif (a == "-" ):
15        print("\nLet's Calculate !!!")
16        print("Subtraction Of",x,"and",y,"is",eval(x)-eval(y))
17
18elif (a == "*"):
19        print("\nLet's Calculate !!!")
20        print("Multiplication Of",x,"and",y,"is",eval(x)*eval(y))
21
22elif (a== "/"):
23        print("\nLet's Calculate !!!")
24        print("Division Of",x,"and",y,"is",eval(x)/eval(y))
25
26elif (a=="**"):
27        print("\nSolution = ",eval(x)**eval(y)) 
28
29else :
30        print("Error : Invalid Operation.")
31
32
33print("Thank You.....")

Watch Video Tutorial