By | 08/08/2019

Python is a popular programming language used for web development, system scripting, machine learning, Data Analysis and so on.
It’s available for many platforms such as Windows, Linux and Mac and from the official web site it’s possible to download all releases.
The latest version is the 3 and, we can use many editor to write Python code such as Visual Studio Code.
If you decide to use VS Code, I advice you to install the Python extensions in order to have many features, like for example the IntelliSense.
Now, we will develop our first easy application in Python, called, with whom will be possible to run the four mathematical operations (addition, subtraction, multiplication and division) using two integer numbers in input.


# we have to import sys in order to use the method exit()
import sys

# definition of a method used for the basic mathematical operations
def MathOperation(value1,value2, operation):
    if operation == "+":
        return value1 + value2
    elif operation == "-":
        return value1-value2
    elif operation == "*":
        return value1*value2
    elif operation == "/":
        return value1/value2
        return "This operation is not available"

# Insert first integer number
val1 = input("Insert the first value: ")

# Input verification
if val1.isnumeric()==False:
    print("Values must be integer")

# Insert first integer number
val2 = input("Insert the second value: ")

# Input verification
if val2.isnumeric()==False:
    print("Values must be integer")

# Insert operation 
operation = input("Select the operation (now are available: +, -, *, /): ")

# run the operation and display the result
print(MathOperation(int(val1), int(val2), operation))

Now, we open a terminal (Terminal->New Terminal) and we run the application with command python3

Output for an unavailable operation:

Output for a wrong value in input:

Leave a Reply

Your email address will not be published.