Episode #23 | Running Python Programs


Wednesday, 06 Feb 2019 Kudzai Nyandoro 12:06 Minutes

Description:

In Episode 17 we installed Python and used Sublime Text to run a small Python program. In this episode, we are going to explore other tools and techniques of running our Python programs using the Python interpreter. An interpreter or virtual machine is a tool that will convert our program into a language that our operating system can understand. Python runs on all operating systems, Mac OSX, Windows, Linux, etc. We will be using Python 3 for this and most tutorials.

Notes:

Type the following to enter into the Python shell.

$ python3

Create the name variable.

>>> name = "Farai"

Create the age variable.

>>> age = 36

Evaluate the name variable.

>>> name

Evaluate the age variable.

>>> age

Create a python file name.py and add the code below.

#name.py
name = "Farai"
age = 35

print("My name is " + name + " and I am " + str(age) + " years old!")

Run the Python program as shown below.

$ python3 name.py

Python Numeric Operators

Addition

>>>  4 + 3

Subtraction

>>> 4 - 3

Multiplication

>>> 4 * 3

Division

>>> 4 / 3

Exponent

>>> 4 ** 3

Floor Division

>>> 4 // 3

Modulus

>>> 4 % 3