1/83
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Reserved Words
Essential vocabulary in Python that cannot be used as Variables
Same
Single and double quotes do the () thing in Python
>>>
“What do you want me to do next?”
Interpreter
Python is an () language
Interpreter Language
Program that analyzes and executes each line of code.
Machine Language
Programming language using binary or hexadecimal instructions that a computer can directly respond to.
Variable
Item that holds a value while a program is running.
Compiler
Program that converts instructions into a machine-code so that they can be read and executed by a computer.
Symbol for quote(s)
‘ or “
String
A sequence of characters enclosed (like a sentence) in single or double quotes
Script
A file that holds Python instructions.
quit()
there is o need to have () at the end of the Python program in the file as it knows to stop when reaching the end.
Sequential execution
Perform statements one after another in the order they are encountered in the script.
Conditional execution
Check for certain conditions and then execute or skip a sequence of statements.
Repeated execution
Perform some set of statements repeatedly, usually with some variation.
Reuse
Give a set of instructions a name so you can use them again whenever you need to.
Syntax errors
An error when you violate the grammar rules of the program, such as forgetting () or quotes
Logic errors
When the program has proper syntax BUT there is a mistake in the order of statements or how they are related. “take a drink from your water bottle, put it in your backpack, walk to the library, and then put the top back on the bottle.”
Semantic errors
Statements are semantically correct AND in the right order, however does not intend what you want it to do (accidentally giving wrong directions)
Debugging
The process of finding the cause of the error in your code.
Random walk programming
Making random changes in the program until it works. Takes a while and can be inefficient.
Main memory
Where in the computer is a variable such as “x” stored after the following Python line executes?
Strings, quotation
() will be enclosed in () marks
Str
Symbol for String
Int
Symbol for Integer
Float (Floating Point)
For the purposes of this coding language, numbers with decimal points like 32.5 (approximate values)
String
The values “17” and “3.2” are what type (Note the quotations, what does that tell you?)
Commas, Quotations
To print an integer don't use () or ()
Bool
Symbol for Boolean
Boolean
A data type with two possible values: True or false
Variable
A name that refers to a value.
Number
Variables CANNOT start with a ()
Lower-case, upper-case
You should start variables with () letters as opposed to () case
Space
You cannot have a () in the variable name.
Statement
a unit of code that the Python interpreter can execute.
Assignment
The process of giving value to a variable is called a(n)
Operators
Special symbols that represent computations like addition and multiplication.
Exponentiation
What does **
mean?
//
To get an integer answer in python as opposed to a floating point in division, what symbol do you use?
%
Modulus operator
Expression, Interpreter
A combination of values, variables, and operators. ONLY WORKS IN AN ()
Concentration, +
Joining the strings by linking them end to end. What is the symbol used?
Multiply
You can also () strings by using *
Addition assignment operator (+=)
adds two values and assigns the sum to a variable (left operand). Ex:X = 5
print("Value Before Change: ", X)
X += 15
print("Value After Change: ", X)
int()
What function is used to convert string values to integers?
\n
What sequence is used to create a newline at the end of statements?
Parse Error
Most common error in Python. Tends to occur when missing parenthesis or other syntax. Make sure parenthesis are balanced so the code runs correctly.
Type Error, integer
A coding error where you combine two objects that are not compatible, such as adding an () and string together.
Store, x = int(x)
int(x) converts the string to an integer, but doesn’t () it anywhere. In this case you may need to use the assignment statement (), as it changes what x references the RETURNED integer value (allowing us to avoid a type error such as adding an integer + string together)
NameError
A common type of error that comes from using a variable before it has a value or simply caused by typos in the code. You can tell if the word only appears once in the code on the right side of the assignment statement.
Variables
You need to keep track of the restrictions needed for your (), and understand what your function is expecting. You can do this by writing comments in your code, or by naming your variables in a way that reminds you of their proper form.
Backwards
Work () from the error. This is because what caused the error usually happens in the code before it.
Automatically
Using commas () inserts spaces
Strings
True and False are not (). There are bool
X is NOT equal to Y
x != y
==
Boolean 56
and, or, not
The three logical operators include (), () and ()
Not
The () operator negates a boolean
Condition
The boolean expression after the if
statement is called the ()
Alternative execution
A second form of an if statement where there are two possibilities and the condition determines which one gets executed. Also known as branches
Elseif
There is no limit on the number of () statements. If there is an else
clause, it has to be at the end, but there doesn’t have to be one.
Chained Conditionals
a "chain" or a combination or multiple conditions
Nested Statements
Simply putting code inside of other code. For example placing an if statement inside of an already existing if statement. Best to avoid or it becomes too messy.
Try, Except
()
and ()
feature in Python as an “insurance policy” on a sequence of statements.
catching an exception
Handling an exception with a try statement
Left, Right
When Python is processing a logical expression such as x >= 2 and (x/y) > 2
, it evaluates the expression from () to ()
Short-circuit evaluation
When the evaluation of a logical expression stops because the overall value is already known (I.E. evaluates the whole statement to be false)
Guard
In the second expression, we say that y != 0
acts as a () to insure that we only execute (x/y)
if y
is non-zero. This evaluation is to prevent a run-time error where it divides the equation by 0.
Green, Red, True, True, 0
() = True Statement (evaluates the whole expression as true and computes
() = False Statement (evaluates whole expression as false so it stops after the initial statement due to short-circuit evaluation)
The third statement produces a run-time error because since the first statement (x) is (), it also assumes the second statement is (). However, since Y is = to (), it attempts to divide it by that value.
Caused
In general, error messages tell you where the problem was discovered, but that is often not where it was ().
ValueError
Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError
. (A built in exception)
Function
named sequence of statements that performs a computation
Argument
a value or variable that we are passing into the function as input to the function. Inside the parenthesis of it.
Return
The result of the argument in a function
Built
The max and min functions that give us the highest/lowest values of each number is () into Python
Len (length)
tells us how many items are in its argument. Spaces ALSO count.
int(), float(), str(), NOT
Type conversion function examples. The int function does () round up
Math Module
provides most of the familiar mathematical functions.
Dot Notation
To access one of the functions, you have to specify the name of the module and the name of the function, separated by a dot. This is known as () () i.e. math.log10(ratio)
Random Module
provides functions that generate pseudorandom numbers
Choice
To choose an element from a sequence at random
Def
indicates that something is a function definition
Header, Body, Header, 4
The first line of the function definition is called the (), while the rest is called the (). The () must end with a : (colon). You should Indent () spaces after the header.
Error
If we move the function call above the definition we will get an ()