An Introduction to Python - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

An Introduction to Python

Description:

Assessment and Evaluation discussion. Python - Summary ... Lightweight syntax prevents students from becoming lost in the picky details of a language. ... – PowerPoint PPT presentation

Number of Views:1360
Avg rating:3.0/5.0
Slides: 40
Provided by: dira9
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to Python


1
An Introduction to Python
Suzanne Dunford Mackenzie High School
  • RCDSB Conference 2007
  • Used and modified with the permission of Michael
    DiRamio NDSB

2
This Session
  • Differentiated Instruction in the Computer class
  • Python Part 1
  • Character education and computers yes!
  • Python Part 2
  • Assessment and Evaluation discussion
  • Python - Summary

3
Differentiated Instruction in the Computer class
  • How does a computer class lend itself to this
    form of instruction?

4
The use of Differentiated Instruction in ICS3M
and ICS4M
  • Computer science classrooms lend themselves to
    differentiated learning
  • Four ways to differentiate Instruction
  • Content/Topic
  • Process/Activities
  • Product
  • Individual Learning Styles

5
Python Part 1
6
Summary - Python Part 1
  • Why Python?
  • Textbooks
  • Documentation in Python
  • IDLE a Python IDE
  • Activity 1
  • Output
  • Activity 2
  • Arithmetic
  • Activity 3

7
Why Python?
  • Why Python, not JAVA, C?
  • UofT makes a choice
  • Python is an interpreted language.

8
Textbook choice
  • Python Programming Second Edition for the
    absolute beginner by Michael Dawson
  • published by Thomson ISBN 1-59863-112-8

9
IDLE A Python IDE
  • Free IDE download at www.python.org
  • Has both interactive window and program files
    (script mode)

Interactions Window
10
IDLE Interaction
  • Allows you to try out an expression with
    immediate results.
  • Output is the result of the expression

11
Script Mode
  • Why script mode?
  • Just choose new program from File

12
Most Important Feature in a Language
Documentation
  • The symbol to start documentation in Python is

13
How do we end the program?
  • raw input (\n\n\Press the enter key to exit.)

14
Activity 1 Exploration of IDLE and Script Mode
  • Purpose to play with the interactions window,
    see what the results are.
  • For the next 5 minutes try printing in IDLE
    (print Hello World) for example.
  • Also, try out the comment symbol and the last
    command
  • Textbook reference pages 11-14

15
IDLE Writing Programs
  • Programs can be written in files, saved, and run.
  • The results are produced in the interactions
    window.

16
Output
  • The output keyword in Python is print. print
    will output anything, Strings, numbers, etc.
  • Note the difference between simply putting
    Hello in the interactions window, and putting
    print Hello

gtgtgt 10 Hello
print 4 6 print "Hello"
program
output
17
Activity 2 First Program
  • Write a program (not in the interactions window,
    in a separate file) that outputs the famous
    quotation To be or not to be on the screen.
  • Run this program (Run -gt Run Module) and see the
    output produced in the interactions window
  • Reference in text book pages 17-24

18
Concatenation
  • String concatenation is the symbol

gtgtgt 'Hello ' 'World' 'Hello World'
19
or ?
  • Python allows you to use either single or double
    quotes for Strings.
  • This prevents needing special characters if you
    want to use a quotation in your string.

gtgtgt print 'This contains "double quotes"' This
contains "double quotes" gtgtgt print "And here are
'single quotes' inside" And here are 'single
quotes' inside
20
Math
  • Uses standard arithmetic operations , -, /, ,
    (remainder)
  • Note if you divide two integers, the result will
    be an integer
  • More math functions like ceiling and floor are in
    the math module (not covered in this session)

21
Activity 3 Division
  • Explore the difference between
  • 5 / 2
  • and
  • 5.0 / 2
  • Textbook Reference pages 25-32

22
Character Education in Programming class
  • Honesty
  • Perseverance
  • Diligence

23
Python Part 2
24
Summary Python Part 2
  • Variables
  • Input
  • Activity 4
  • Looping
  • Activity 5
  • Selection
  • Activity 6

25
Variables
  • Python variables dont carry type.

gtgtgt x 6 gtgtgt print x 3 9 gtgtgt x "Hello" gtgtgt
print x Hello gtgtgt print x " world" Hello world
26
Input
  • The method raw_input(string) returns a string the
    user has typed in
  • The parameter to raw_input is the prompt given to
    the user.

x raw_input("ltTYPE SOMETHINGgt") print "The user
typed " x
Program
gtgtgt ltTYPE SOMETHINGgtThis is my input The user
typed This is my input
Output
27
Input cont
  • The string input can be converted to other types
    using conversion methods like int(string) and
    float(string)

x raw_input("ltTYPE A NUMBERgt ") y
int(x) print y 2
Program
gtgtgt ltTYPE A NUMBERgt 11 22
Output
28
Activity 4 Input Conversion
  • Write a program that reads in a temperature in
    Fahrenheit and converts it to Celsius
  • C (F - 32) 5 / 9
  • Textbook reference32-46

29
Indentation
  • Python doesnt use brackets to define blocks of
    code
  • Indentation tells the program where a section
    ends
  • If a program isnt properly indented you will get
    an error

30
Loops
gtgtgt 0 1 2 3 4 5 6 7 8 9 done!
i 0 while i lt 10 print i i i
1 print "done!"
  • The loop continues iterating as long as the
    condition following while remains true

Program
Output
31
Activity 5 Importance of Indentation
  • Create a program that uses a loop, like the
    previous example.
  • Now remove the indentation and try running the
    program
  • Textbook reference51-58

32
Comparisions
  • is used for equality testing
  • Inequality is !
  • Inequalities are straight forward lt, gt, lt, gt

gtgtgt print 8 lt 15 True gtgtgt print 9 ! 7 True
Interactions Window
33
Selection Statements
  • if/elif/else
  • Must have one if clause
  • Followed by 0 or more elif (else if) clauses
  • Followed by 0 or 1 else clause

34
Selection Statements Example
  • Notice what happens when you remove the
    indentation.

x raw_input("input please") x int(x) if x lt
10 print "Small" elif x lt 20 print
"Medium" elif x lt 30 print "Big" else
print "HUGE!" print "Done"
gtgtgt input please21 Big Done
Program
Output
35
Activity 6 Selection
  • Write a program that reads in a number and
    determines if that number is even or odd.
  • Textbook reference page 59 65

36
Assessment and Evaluation
  • Using same principles of honesty, perseverance
    and diligence in our assessment and evaluation
  • Group discussion

37
Summary of Python
38
Use in Computer Programming
  • Free IDE
  • The interactions window allows students to
    quickly test out ideas.
  • Lack of brackets keeps code uncluttered.
  • Students must indent their code properly or it
    wont function properly.
  • Lightweight syntax prevents students from
    becoming lost in the picky details of a language.

39
Thanks again to Michael DiRamio.
  • Plug Michael is giving a talk at the ACSE
    conference Nov. 10 on a different topic.
Write a Comment
User Comments (0)
About PowerShow.com