专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python

Python was created in 1991. It has been espcially popular in recent years.
专业英语笔记:Install and Use Python

Since Python is so popular and useful, we need to learn something about Python programming.

Download Python from its official website.

专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python

Create a new folder python at c:\.

专业英语笔记:Install and Use Python

Double-click the Python installer and install Python at the location of C:\python.
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python

First let's start the command-line Python from the start-menu.

专业英语笔记:Install and Use Python
You will see a DOS window and the Python prompt: >>>

专业英语笔记:Install and Use Python

Now we can use Python in an interactive manner. 

This manner is very convenient for us to learn Python grammar.

Task 1. Print a message on the screen.
专业英语笔记:Install and Use Python
Task 2. Complete the addition of two integers.
专业英语笔记:Install and Use Python
The interactive manner in Python is similar to that in Visual Basic.
专业英语笔记:Install and Use Python

Task 3. Take different actions according to the age input from the keyboard.

专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python
Let's complete the same in another way. We can write a Python program to do this.

All roads lead to Rome. 条条道路通罗马。

Now let me start IDLE from the start-menu as follows:

专业英语笔记:Install and Use Python
We will see a Python shell on the screen:

专业英语笔记:Install and Use Python


Firstly, let me try the interactive manner here.

专业英语笔记:Install and Use Python
Secondly, let me complete the same task in program manner.
Click File menu, choose New File, and you will see an editor window like this:

专业英语笔记:Install and Use Python


Now we can write codes in the text editor as follows:

专业英语笔记:Install and Use Python

Save the file to a Python program with the extension of ".py".
专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python

专业英语笔记:Install and Use Python
Run the Python program "addition.py".
专业英语笔记:Install and Use Python
专业英语笔记:Install and Use Python
Now we modify the source program so we can input two integers from the keyboard and calculate its sum.

专业英语笔记:Install and Use Python

Run the program again and we can something like this:

专业英语笔记:Install and Use Python

Where is the Python program - addition.py?

专业英语笔记:Install and Use Python

What shall we do to run a Python program if we don't use the IDLE?

1. start DOS window

专业英语笔记:Install and Use Python

2. enter the directory c:\python_work

专业英语笔记:Install and Use Python

3. Run the python program addition.py

专业英语笔记:Install and Use Python