User:Mkjayananda/My sandbox

From WikiEducator
Jump to: navigation, search

Basic Programming Concepts

OER name : Basic Programming Concepts

Category:    Computer Science

Objective:   The main objective of this course is to teach basic programming skills to students who have never learned programming before. Python was used as the language to teach because it is considered an excellent language for teaching programming to beginners.

Target group: A/L students

Licensing information: CC BY

Readers are free to copy and distribute the text; they are also free to modify it, which allows them to adapt the book to different needs, and to help develop new material.

Copyright notice: This course is based on How to Think Like a Computer Scientist: Learning with Python by Allen Downey et al. (2002), which is avaible under GNU Free Documentation License

Lesson 1: What is a program?

A program is a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or (strangely enough) compiling a program.

The details look different in different languages, but a few basic instructions appear in just about every language:

Get data from the keyboard, a file, or some other device.
Display data on the screen or send data to a file or other device.
Perform basic mathematical operations like addition and multiplication.
conditional execution
Check for certain conditions and execute the appropriate sequence of statements.
Perform some action repeatedly, usually with some variation.

Believe it or not, that’s pretty much all there is to it. Every program you’ve ever used, no matter how complicated, is made up of instructions that look more or less like these. Thus, we can describe programming as the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.

That may be a little vague, but we will come back to this topic later when we talk about algorithms.

Before next lesson: Installing Python

In order to go through the following lessons, you will need to install Python in your computer. The video below shows you how to do this.

Python : Installation in windows 7

Lesson 2: The first program

Traditionally, the first program written in a new language is called "Hello, World!" because all it does is display the words, "Hello, World!" In Python, it looks like this:

print "Hello, World!"

This is an example of a print statement, which doesn't actually print anything on paper. It displays a value on the screen. In this case, the result is the words

Hello, World!

The quotation marks in the program mark the beginning and end of the value; they don't appear in the result.

Some people judge the quality of a programming language by the simplicity of the "Hello, World!" program. By this standard, Python does about as well as possible.