Introduction to Python Programming

adventurescoldΛογισμικό & κατασκευή λογ/κού

7 Νοε 2013 (πριν από 3 χρόνια και 1 μήνα)

137 εμφανίσεις

Introduction to Python Programming
Lu´ıs Pedro Coelho
Programming for Scientists
January 14,2009
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (1/14)
What is a Computer?
1
Memory
2
Processor
3
Magic
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (2/14)
Python Model
1
Objects
2
Operations on objects
3
Magic
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (3/14)
Computer Program
helloword.py
print'Hello World'
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (4/14)
Running a Program
1
Shell
2
IDE
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (5/14)
Let me show you a demonstration...
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (6/14)
More Complex Example
What is 25 + 20%?
print 25
*
1.2
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (7/14)
More Complex Example
What is 25 + 20%?
print 25
*
1.2
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (7/14)
Tip Calculator
Calculator
1
Input:initial amount and the tip percentage.
2
Ouput:final amount.
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (8/14)
Blackboard demonstration
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (9/14)
Flow of Control:Conditionals
Tip Calculator (II)
1
Input:initial amount and service quality.
2
Output:final amount.
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (10/14)
Conditionals
if <condition>:
<statement 1>
<statement 2>
else:
<statement 3>
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (11/14)
Lists
students = ['Luis','Mark','Rita']
print students[0]
print students[1]
print students[2]
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (12/14)
Loops
students = ['Luis','Mark','Rita',...]
for st in students:
print st
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (13/14)
Loops (II)
students = ['Luis',...]
looking_for ='Anna'
i = 0
while students[i]!= looking_for:
i += 1
if students[i] == looking_for:
print'Found her'
else:
print"Sorry,she's not registered!"
Lu´ıs Pedro Coelho (Programming for Scientists)?Introduction to Python Programming?January 14,2009 (14/14)