Intro To Python Flashcards
What is an algorithm?
A step by step list of instructions that if followed exactly will solve the problem under consideration
What is the goal in computer science?
Is to take a problem & develop an algorithm that can serve as a general solution
What is the most important skill for a computer scientist?
To be able to solve problems
True or false. High-level languages are easier to program in
True
They take less time to write
They are shorter and easier to read
They are more likely to be correct
They are portable = can run on all different kinds of computers
Source code is another name for what?
The instructions in a program, stored in a file
Python is a high-level language, but must be interpreted into machine code called “_______” before it can be executed
Binary
It is high-level if the program must be “__________” before it can run
It is low-level if the computer can execute it w/out “_________ __________”
Processed
Additional processing
What is the difference between compilers and interpreters?
Compilers:
- take the entire source code & produce object code
Ex. Translating an entire book
Interpreters:
- execute the code line by line
Ex. Translating a line at a time in a book
Computing science is the study of “__________”
Algorithms
What is a programming language?
Provide a set of instructions & syntax rules for writing code that can implement algorithms to perform specific tasks or problems
What is the role of the python interpreter?
Translation process?
Computer execution?
Source code —> python interpreter —> output/results
Translation process:
- transforms code into language the computer understands
Computer execution:
- translated code —> sent to computer for execution
What are “code blocks” in python?
Sections of code that tell the computer to do something specific
Can include loops, functions, and if statements etc…
Need “____” to run python code
This is like a “_______” write down what is made & follow instructions step by step
IDE (integrated development environment)
**NOTE: in CMPUT 101 we use IDLE (integrated development and learning environment)
Recipe
Python code is executed from “_____” to “_______”
Top to bottom
“Hello world” is what?
A string
Can use single or double quotations
How do you concatenate (join) strings together in python?
Do this by using the “+” operator
Ex. “Hello” +” “ + “World”
Who or what typically finds syntax errors?
The compiler / interpreter
What is a syntax error?
Give an example…
Syntax refers to the structure of a program and the rules about that structure
Ex. Forgetting a colon at the end of a statement where one is required
What is a runtime error?
Called this because the error does not appear until you run the program
Rare in the simple programs seen in the first few chapters
Ex. Attempting to divide by zero
What typically finds runtime errors?
The interpreter
If an instruction is illegal to perform at that point in the execution
The interpreter will stop with a message describing the exception
What is a semantic error?
Give an example
If there is one in your program it will run successfully in the sense that there is no error messages
HOWEVER the problem is that your program you wrote is not the program you wanted to write
The program or ‘sementics’ is wrong
Ex. Forgetting to divide by 100 when printing a percentage amount
- will give a wrong answer because the programmer implemented the solution incorrectly
Who or what typically finds semantic errors?
The programmer
You must fully understand the problem so that you can tell if your program properly solves it
What is the difference between programming and debugging?
Programming is the process of writing the source code
Debugging is the process of finding and correcting all the errors w/in the program until it is correct
Programming languages are “______” languages that have been designed to express computations
Formal