Lecture2introductiontopython 130525013928 Phpapp01
Lecture2introductiontopython 130525013928 Phpapp01
Computational Thinking
Module 2 :
Introduction to Python
Computational Programming
Thinking Run on
Computational Programming
Thinking Run on
C
Java
Note: here is in
my windows 32-bit
platform (win XP)
1 2
4
3
5 6
In more detail…
• A program consists of a sequence of
instructions to perform an algorithm
Four
instructions
only
You may use your favorite text editor (or just use the IDLE
editor) to create a text file, type in the python instructions
line by line, and then save it as in a file with file extension .py
Module 2 : Introduction to Python 24 of 46
Use IDLE
• Start IDLE, which is a Python Graphical User Interface
(assume you’ve already installed it)
run it!!!
Print
out
Print
out
Print
out
Print
out
One more
instruction
More
print out
Here we add one more instruction that combines the two strings
“str1” and “str1”; then, we print out the result!!! Here we can
actually read back the values of the strings!!!
(Note: you will learn this + operator for string later in this course: module 8)
Let’s try
more
Like an
interactive Ok with Python 2
calculator but not Python 3
Need parenthesis
Read
input
The
algorithm
Display Note: you will learn detail on if, else, print, for, etc. later
result Module 2 : Introduction to Python 35 of 46
Same Algorithm in C
• More initialization and formality are required in C
compared to Python
compile run
Program Machine
Code in C Code
Store as a file
translate run
Python Machine
Program Code
Interpreter
Module 2 : Introduction to Python 42 of 46
Python – Interactive and Interpreted