Concepts of programming - Programs instructions that a computer can understand

Pybeginner
By -
0



Here we will be explaining some concepts that are widely used in Computation and Programming.

Programs instructions that a computer can understand

A computer program can understand different types of instructions such as, Numbers, Words, Images, etc.

Here we will show some examples of the three above mentioned examples.

Compute with Numbers

Computers were first used for calculations. You may be used to doing calculations with a calculator, but calculations are often easier if you can name the numbers you are working with. When you name a number, or the result of a calculation, you are creating a variable. A variable is a name associated with computer memory that can hold a value and that value can change or vary. One example of a variable is the score in a game. The score starts off at 0 and increases as you play the game.

Compute with Words

The computer can also compute with words, or more accurately, with strings which are sequences of characters. We can create a string by typing characters between a pair of single ('Hi'), double ("Hi"), or triple quotes (‘’’Hi’’’). We can “compute” with strings using some of the same basic arithmetic operators – they just mean something different here. Here we generate silly song lyrics by using + to combine (append) two strings and * to repeat strings.

Compute with Images

Pictures on a computer are broken up into little bits called pixels, for picture (pix) elements (els). These are laid out on a grid, from left to right (the horizontal or x dimension) and top to bottom (the vertical or y dimension).
 



Figure 1: A grid with horizontal (x) and vertical (y) dimension

 

Pixels are quite small. Even this small picture below has 180 columns and 240 rows of pixels:

Each pixel has a color associated with it: An amount of red, an amount of green, and an amount of blue. The amount can be in the range of 0 to 255 where 0 is none of that color and 255 is the maximum amount of that color. A pixel is displayed using light, not paint, so it may work a bit differently than you might expect if you only have experience making colors by mixing paint. For example, you would mix blue and yellow paint to make green, but you mix red and green light to make yellow light.



 

 

Concepts from computing 


This defines the following concepts from computing:

Code - Code is a set of instructions that a computer can understand. This is sometimes called a program.

Comment - Comments explain what we’re doing in the programs and are intended to be read by people, not computers. In Python a comment starts with #. The computer will ignore everything from the start of the comment to the end of that line.

Dot-Notation - Dot-notation is how you ask an object to do something . You use the name of the object followed by a dot (period) and then followed by what you want it to do and then any values in parentheses. For example to return a new string will all lowercase letters from a variable called sentence use sentence.lower(). To ask a turtle named alex to go forward 50 units use alex.forward(50).

Library - A library is a group of programs that provides some functionality. The Turtle library is a good example. It lets us create and work with Turtle objects.

Pixel - A pixel is one small part (element) of a picture. Pixels are stored in a grid and have both x (horizontal) and y (vertical) values. A pixel has a color which can be defined by an amount of red, green, and blue with values from 0 to 255.

Program - A program is a set of instructions that a computer can understand to accomplish some goal. This is sometimes called code.

Screen - A Screen is part of the Turtle library. It is a space on the page for the turtle to move in and draw on.

String - A string is anything we can type between a pair of pair of single quotes ('Hi'), double quotes ("Hi"), or triple quotes ('''Hi'''). It is a sequence of characters.

Variable - A variable is a name associated with computer memory that can hold a value and that value can change or vary. One example of a variable is the score in a game.


Post a Comment

0Comments

Post a Comment (0)