142-253 Computer Programming BSc in Digital Media, PSUIC Aj. Andrew Davison, CoE, PSU Hat Yai Campus E-mail: ad@fivedots.coe.psu.ac.th 1. Starting
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.
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
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
Python Webpage http://www.python.org click here
Python Download Page click here
Wait for Installer to Appear on your PC
Start Installer click here
Click PATH & Press "Install Now"
Setup in Progress
Press Close at End of Installer
Check the Menu for Python
2. Starting Python There are lots of ways of starting Python from the Python menu, start IDLE (a Python editor) from the Python menu, start Python start Python from the Windows command line (2) and (3) start the same Python The easiest
2.1. Start IDLE (a Python editor)
Inside IDLE I typed help() and <enter> to start "help" I typed quit to leave "help" but still be in IDLE
Get Python to do Things I typed these and <enter>
Some Math Operations no fraction part remainder 2 to the power 5 no fraction part and ( ... ) around the maths, if you want
Some Maths to Try
Leaving IDLE and Python
Other Ways to Leave IDLE >>> exit() Any one of these >>> quit() There are various ways to quit interactive Python. There are two commands which are equivalent for our purposes: quit() and exit(), but the simplest is the key sequence [Ctrl]+[D]. >>> Ctrl D +
2.2. Start Python (but no editor)
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
Start Python from Windows Command Line Start Windows "Command Prompt" program
2.3. Start Python in the Command Window I typed python and <enter> to start "python"
Leaving Python in the Command Window 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 but still be in the Command Window
3. Programming with Python in IDLE
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
Create a new Program File
Write a Program into the File
Save the program file
Type in a File name I'm saving the file as "test1" on the Desktop
Check the file is on your PC The file is called "test1.py" on the Desktop
5. Running your Program Two ways: run your program inside IDLE run your program in the Command Window
5.1. Running your Program in IDLE
Open (Load) test1.py
Run the program using "Run Module" (F5)
Python Runs (Executes) your Program
5.2. Run from the Command Prompt I typed cd Desktop to move to the desktop This is the program running. I typed python test1.py to run the program
6. Python Documentation (docs)
Or from Help in IDLE
The First Doc Page