Jump to content

User:Sdudah/python

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sdudah (talk | contribs) at 14:05, 10 April 2007 (Functions (divide and conquer) (2m)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Computer Programming Lesson Plan


Goals

  • Learn how to program the computer
  • Be a free opensource community member

Objectives

  • Learn some basic programming concepts and constructs: Variables, If, For and Functions
  • Learn what a flowchart is
  • How to make a flowchart for writing programs

Variables (1m)

What is a variable?
x, university, car

Assignment NOT equality
x=5.2, university="Queen's"

Drill (1m)

Think of other examples of variables? z, first-name, school, person 
x=3+7 ?
count=4 
x=2+count ? 
x=2
y=x+8 ? 
x=x+3 ?


Flow Control

IF statement (2m)

What makes computers look intelligent?

Simple check

age=20
IF (age < 18)
   Print "Sorry, you are still young"

More intelligence

age=20

IF(age < 18)
    Print "Sorry, you are still young"
ELSE
    Print "You can drive a car"

Looping: For statement (1m)

Execute commands many times

'What does the next statement do?'

FOR i=1  TO   i=100   DO
    Print "I want to drive a car"

Functions (divide and conquer) (2m)

What is a function?
A subprogram (sub-code). Think of it as a small program you want it to solves you small problems.

output value = FUNCTION( input parameters)

How does it work?

  • call it and give it "orders"
  • it processes, cooks, crunches... (in a bit of time)
  • Gives you the stuff back
 height= sin(30)
 height= height * 10
 Print "The height of the building is "  height

What are advantages of functions?

  • Some functions are ready for you to use (sin, cos, time, print)
  • Make large programs easier ( user defined functions )
  • Team work (several programmers work on different parts of a project)
  • debugging (easier to debug and fix)

FLOWCHART

A simple flowchart

Essential components of a basic flowchart (1m)

START END ENTER PRINT PROCESS DECISION
start end enter print process decision


Example of a flowchart (1m)


If you heard of flowcharting, why would you use a flowchart for?

  • you do not need a programming language to "write down" a program. You visually write a program.
  • Helps you get the big picture.
  • you can add details any time later.
  • Visually, understand the problem better. You can spot missing points.
  • Translate the flowchart into a program (think of pseudo-code).
  • Translate the flowchart into any programming language (abstraction).

Flowchart exercise: Make a simple flow chart to/for

Questions

  1. Write three computer programming languages you know or heard of?

Ex: C, C++, Java, Python

  1. With the goal of promoting free opensource community, what would you (currently) do to learn a new programming language?

Possible answers:

  1. Free opensource OS, Linux (recommended)
  2. Free Book/Tutorials. Ex:Wikibooks project),
  3. Free opensource compiler Ex: www.python.org
  4. Free opensource editor. Ex: Emacs, Eclipse, etc
  5. Programming language Newsgroup/Language-specific Mailing list. Ex: comp.lang.python
  6. Participate in a community project. Ex: coding. Others (documentation, report bugs, donate,promote).
  7. Programming contest (if you have previous programming experience) Ex: Google summer code contest.Get hired?

Feedback

(you can submit answers to the follwoing questions electronically on the course website with the case-sensitive password:I.lovE.PyThOn)

  • What did you like to know more about that was covered today?
  • What is it that you felt was not clear today? be specific and give exmaples where possible?
  • Is there something that you wish be covered?
  • From a scale of 1-5, how would you rate the lab session?
  • Comments: any positive criticism that would help make future lab sessions better?

Resources: