An Introduction to Python (TEJ3M & TEJ4M)
What is a Programming Language? A high-level language is a programming language that enables a programmer to write programs that are more or less independent of a particular type of computer. Such languages are considered high-level because they are closer to human languages and further from machine languages. high-level languages you might have heard of are Turing, Python, C or C++, Java and Perl. programs written in a high-level language have to be translated before they can run which is a small disadvantage of high-level languages.
What is a Programming Language? (continued) Low-level languages, are sometimes called machine language or assembly language. Low-level programs can only run on one kind of computer, and have to be rewritten to run on another. high-level languages are portable, meaning that they can run on different kinds of computers with few or no modifications. almost all programs are written in high-level languages.
What is a Programming Language? (continued) There are two ways to translate a program: interpreting and compiling. An interpreter is a program that reads a high-level program and does what it says, translating the program line-by-line, alternately reading lines and carrying out commands. A compiler is a program that reads a high-level program and translates it all at once, before running any of the commands.
What is a Programming Language? (continued) The compiler translates source code into a language the computer can understand, machine language (the computer understands binary language which are 0 s and 1 s) How it works: 1) Source code is compiled into object code 2) Object code is combined with library files by a linker 3) Produces the file that can be executed by the computer (executable file)
What is a Programming Language? (continued) structured programming is the idea that within a program there are groups of statements that are used to control the flow of information. These groups of statements are called control constructs which consists of: 1) linear sequence: where statements are executed one after the other in the order in which they are written. 2) repetition: where a group of statements is to be executed repeatedly. 3) selection: where one group of statements is selected for execution from a number of alternatives.
What is a Programming Language? (continued) Structured programming refers to a systematic way of analyzing computer problems and designing solutions called top-down programming. In top-down programming, a problem is broken down into a series of smaller problems, each of which is then solved. Once the smaller problems are solved, the solutions are combined to solve the larger problem.
What is a program The instructions look different in different programming languages, but there are a few basic operations most languages perform: 1) input: Get data from the keyboard, or a file, or some other device. 2) output: Display data on the screen or send data to a file or other device. 3) math: Perform basic mathematical operations like addition and multiplication. 4) testing: Check for certain conditions and run the appropriate sequence of statements. 5) repetition: Perform some action repeatedly, usually with some variation.
Debugging programming errors are called bugs and the process of tracking them down and correcting them is called debugging. There are a three kinds of errors that can occur in a program: 1) Syntax Errors 2) Run-time Errors 3) Logic Errors
Syntax Errors Syntax refers to the structure of your program and the rules about that structure. In English, a sentence must begin with a capital letter and end with a period. Compilers are not forgiving. If there is a single syntax error anywhere in your program, the compiler will print an error message and quit, and you will not be able to run your program. The syntax rules are different for various programming languages.
Run-time Errors In Java, run-time errors occur when the interpreter is running the byte code and something goes wrong. Java and Turing tend to be a safe languages, which means that the compiler catches a lot of errors. So run-time errors are rare, especially for simple programs.
Logic Errors If there is a logic error in your program, it will compile and run without generating error messages, but it will not do the right thing. Specifically, it will do what you told it to do. Identifying logic errors can be tricky because you have to work backwards, looking at the output of the program and trying to figure out what it is doing.