The Zen of Python - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

The Zen of Python

Description:

The Zen of Python import this What makes a good program? Where we are Mock exam next week, period 4 Will be screen based, requiring coding Then five and a half ... – PowerPoint PPT presentation

Number of Views:144
Avg rating:3.0/5.0
Slides: 13
Provided by: Mr155
Category:
Tags: python | zen

less

Transcript and Presenter's Notes

Title: The Zen of Python


1
The Zen of Python
  • gtgtgt import this

2
What makes a good program?
3
Where we are
  • Mock exam next week, period 4
  • Will be screen based, requiring coding
  • Then five and a half weeks between half term and
    Easter.
  • And three weeks before your real exam Monday
    11th May

Most of you need practice. Just practice. So
please come on Wednesday
4
Miss Matthews Task
  • Input two values, height and width
  • Calculate (heightwidth)/2 and output the result
  • Simple . but ..
  • Everyone got it wrong. Why?

5
Python division
  • What is 2/3?
  • Try it .. gtgtgt print 2/3

6
Import from the future
  • from __future__ import division
  • Or
  • float(width)

Now fix it!
7
Turn this into a function
  • Objective .
  • Create a function
  • With two arguments length and width
  • Get the value back, (lengthwidth) / 2
  • Need the keyword return

8
Whats wrong with this?
  • def absolute_value(x)
  • if x lt 0
  • return -x
  • if x gt 0
  • return x

Now do it!
9
The docstring
  • def myweirdfunction(length)
  • Draws a line of breadcrumbs which the cursor
    has to follow takes single integer argument
    length
  • dostuff
  • Print myweirdfunction.__doc__

10
Turn it into a module
  • Main code section
  • def main()
  • do stuff
  • if __name__ __main__
  • main()

Try it out
11
Writing a good program
  • Structure
  • Modules
  • Functions
  • Documentation strings
  • Highlighting the actual program

12
The Zen of Python
  • gtgtgt import this
Write a Comment
User Comments (0)
About PowerShow.com