01. Starting Pythonx

Download Report

Transcript 01. Starting Pythonx

Let’s Learn
Saenthong School, January – February 2016
Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
E-mail: [email protected]
1. Starting
1
0. Computers and Programs
 A computer is a machine that
stores data.
 A program is a set of instructions that tells a computer
what to do with the data.
2
Why Learn to Program?
 Makes you a clever
user of computers
 It's fun!
 You make stuff (programs) that do things
 Helps you learn problem solving skills
 Programmers get jobs
3
Why Learn Python?
The Python programming language is aimed at
beginners
It's easy to learn and use
Powerful
Lots of program libraries
Free
Runs on everything
Lots of users; lots of help online
Used in the real world
1. Installing Python on your PC
1. Go to the Python webpage
2. Download version 3.5.1 (or higher)
3. Wait a while ...
4. Start Installer
5. Click PATH and press "Install Now"
6. Click "Close" at end
7. Check the Menu for Python
6
Python Webpage
http://www.python.org
click
here
7
Python Download Page
click
here
8
Wait for Installer to Appear on
your PC
9
Start Installer
click
here
10
Click PATH & Press "Install Now"
11
Setup in Progress
12
Press Close at End of Installer
13
Check the Menu for Python
14
2. Starting Python
There are lots of ways of starting Python
1. from the Python menu, start IDLE (a Python editor)
The easiest
2. from the Python menu, start Python
3. start Python from the Windows command line
 (2) and (3) start the same Python
15
2.1. Start IDLE (a Python editor)
16
Inside IDLE
I typed help() and
<enter> to start "help"
I typed quit
to leave
"help" but
still be in
IDLE
17
Get Python to do Things
I typed these
and <enter>
18
Some Math Operations
and ( ... ) around the maths, if you want
19
Some Maths to Try
20
Leaving IDLE and Python
21
Other Ways to Leave IDLE
>>> exit()
>>> quit()
Any one
of these
>>> Ctrl + D
22
2.2. Start Python (but no editor)
23
Inside Python
I typed help() and
<enter> to start "help"
I typed quit
to leave
"help" but
still be in
Python
I typed ctrl-Z and
<enter> to leave Python
24
Start Python
from Windows
Command Line
Start
Windows
"Command
Prompt"
program
25
2.3. Start Python in the
Command Window
I typed python and
<enter> to start "python"
26
I typed help() and
<enter> to start "help"
Leaving Python in
the Command Window
I typed quit
to leave
"help" but
still be in
Python
I typed ctrl-Z and
<enter> to leave Python
but still be in the
Command Window
27
3. Programming with Python in IDLE
28
29
4. Writing a Python Program
1. Start IDLE
2. Create a new program file
3. Write a Python program into the file
4. Save the program file.
 give the file a name, e.g. test1
5. Check the file is on your PC
30
Create a new Program File
31
Write a Program into the File
32
Save the program file
33
Type in a File name
I'm saving the file as
"test1" on the Desktop
34
Check the file is on your PC
The file is called
"test1.py" on the
Desktop
35
5. Running your Program
Two ways:
 run your program inside IDLE
 run your program in the Command Window
36
5.1. Running your Program in
IDLE
37
Open (Load) test1.py
38
Run the program using "Run
Module" (F5)
39
Python Runs (Executes) your
Program
40
5.2. Run from the Command
I typed cd
Prompt
Desktop to
move to the
desktop
This is the
program
running.
I typed
python
test1.py to
run the
program
41
6. Python Documentation (docs)
42
Or from Help in IDLE
43
The First Doc Page
44