1 / 12

The Zen of Python

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 weeks between half term and Easter. And three weeks before your real exam – Monday 11 th May.

Download Presentation

The Zen of Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Zen of Python >>> 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 (height*width)/2 and output the result • Simple …. but ….. • Everyone got it wrong. Why?

  5. Python division • What is 2/3? • Try it .. >>> 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, (length*width) / 2 • Need the keyword return

  8. What’s wrong with this? def absolute_value(x): if x < 0: return -x if x > 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 >>> import this

More Related