Unit 6
Fundamentals of Programming
Introduction
- A computer program is a set of instructions that commands a computer what to do.
- Computers do every task they do by following the instructions stated in programs, and the people who write programs are called programmers.
- This unit introduces the types of programming languages, then teaches the basics of one of them, Python: the interactive interpreter and the text editor, variables and data types, statements and expressions, and simple programs with input and output.
- Every Python listing in this unit has a Run button.
- Boxes whose lines begin with >>> work like the interactive interpreter: each line is run in turn and its result is shown under it.
- The other boxes are scripts, as written in the text editor, and they show only what print() displays.
- Press Edit to change a box and run it again.
π― Learning Outcomes
- Define computer programs.
- State and describe the types of programming languages.
- Explain the syntax and semantics of programming languages.
- Explain variables and data types.
- Differentiate statements and expressions in Python.
- Analyze simple programs written in Python.
- Write simple programs with input and output.
6.1 Computer Programs and Programming Languages
- Programming languages are computer languages used to write computer programs.
- They are generally grouped into machine language, assembly language and high-level language.
6.1.1Types of Programming Languages
Machine Language
- Machine language is a low-level language in which everything, including instructions, numbers and memory locations, is represented in 1s and 0s, the binary system.
- It is the language computers understand directly, with no translation, which is why it is very fast and uses memory efficiently.
- Writing programs in machine language, however, is very difficult.
Assembly Language
- Assembly language is also a low-level language, but instead of 1s and 0s it uses symbols called mnemonics.
- It is easier than binary but still difficult.
- Because computers understand only machine language, a program written in assembly language needs special software, the assembler, to translate its instructions into machine language.
High-Level Language
- High-level languages are closer to human languages than assembly and machine languages are.
- They let programmers concentrate on the problem they want to solve more than on the language.
- Examples are C, C++, Java, C#, Python, Perl and Ruby.
- A high-level program also cannot be executed directly: it is first translated into machine language by translator software, which is either a compiler or an interpreter.
| Translator | What it translates | How | Used by |
|---|---|---|---|
| Assembler | Assembly language | Translates the instructions into machine language | Assembly language |
| Compiler | High-level language | Translates the whole program at once; the machine language is then executed | C, C++, Java, C# |
| Interpreter | High-level language | Translates and executes the program one statement at a time | Python, Perl, Ruby |
6.1.2Syntax and Semantics
π
The rest of Unit 6 is in the Danulearn app
Read the full notes for all 5 sections, worked examples and figures, plus 11 exercises with step-by-step solutions, the Short Note and the unit review.
π Contents
- 6.1Computer Programs and Programming LanguagesPreview
- 6.2Basics of Pythonπ
- 6.3Variables and Data Typesπ
- 6.4Statements and Expressionsπ
- 6.5Writing a Simple Programπ