Unit 3 Vocab
- Lessons so far
- Vocab:
- Variables
- Data Types
- Assignment Operators
- Lists
- 2D Lists/ Arrays (Matrix)
- Algorithms
- Expressions:
- Comparison Operators:
- Boolean Expressions and Selection/Iteration:
- Truth Tables:
- Characters
- Strings:
- Length:
- Concatenation:
Lessons so far
- 1: Sections 3.1 and 3.2: Variables, Assignments, and Data Abstractions
- 2: Sections 3.3 and 3.4: Mathematical Expressions and Strings
- 3: Sections 3.5, 3.6, and 3.7: Boolean Expression, Conditionals, and Nested Conditionals
- 4: Sections 3.8 and 3.10: Boolean Iteration and Lists
- 5: Sections 3.9 and 3.11: Developing Algorithms and Binary Search
- 6: Sections 3.12 and 3.13: Calling and Developing Procedures
- 7: Sections 3.14 and 3.15: Libraries and Random Values
- 8: Section 3.16: Simulations
- 9: Sections 3.17 and 3.18: Algorithm Efficiency and Undecidable Problems
fruit = "apple" #fruit is the name, 'apple' is the value, and string is the type
score = 0 #score is the name, 0 is the value, integer is the type
integer = 9
string = "words" #surrounded by quotations
boolean = False # True or false
Lessons that discuss this:
- Lesson 1
- Lesson 2
Assignment Operators
Allows a program to change the value or variables
Operator | Description | Syntax | Outcome when print |
---|---|---|---|
= | Assign value of right to left | a = b | b |
+= | Adds right and left together and assigns that value to right | a += b | a + b |
-= | Subtracts left from right and assigns that value to right | a -= b | a - b |
*= | Multiplies right with left and assigns that value to left | a *= b | a * b |
/= | Divides left with right and assigns that value to left | a /= b | a / b |
**= | Calculates exponent(raise power) value using and assigns that value to left | a **= b | a ^ b |
Lessons that discuss this:
- Lesson 1
- Lesson 2
Lists
A sequence of values stored under one variable. Used to store multiple related values under one label and help organize code better
fruits = ["apple", "pear", "banana"]
scores = [90, 87, 45]
tic_tac_toe =[["0", "X", "0"],
["0", "0", "X"],
["X", "X", "0"]]
# one way to print w/ dimensionality:
m = 0
while m < len(tic_tac_toe):
print(*tic_tac_toe[m]) # the * tells the program to print the values as strings
m = m + 1
info = {"name": "Ekam",
"grade": 11,
"YOB": 2006}
print(info["name"]) #putting a key in square brackets causes the value to be printed
Lessons that discuss this: ??
Algorithms
A set of instructions that can can achieve a task
Lessons that discuss this:
- Lesson 2
Sequencing, Selection, and Iteration
Parts of an algorithm:
- Sequencing: The specific order of the steps of an algorithm. Changing the sequencing can change the outcome
- Selection: Making a decision (if this is true, do these steps.. if not, do these steps)
- Iteration: Repeating a part of code for a defined number of times, or even forever (while loops)
Lessons that discuss this:
- Lesson 2
Expressions:
Mathematical expressions that can be put into code
Operation | Syntax |
---|---|
x + y | Addition |
x - y | Subtraction |
x * y | Multiplication |
x / y | Division |
x // y | Quotient |
x % y | Remainder |
x ** y | Exponentiation |
Lessons that discuss this:
- Lesson 2
Comparison Operators:
Used to compare two values with each other.. useful in Boolean expressions
Operator | Description |
---|---|
> | Greater than |
< | Less than |
== | Equal to |
!= | Not equal to |
>= | Greater than or equal to |
<= | Less than or equal to |
Lessons that discuss this:
- Lesson 3
Boolean Expressions and Selection/Iteration:
Boolean is whether something is true or false. Selections can be made based on boolean expressions, where different outcomes are given when something is true or false. One type of selection could be whether to repeat a certain loop or not, and the decision is made based on a Boolean expression. This could be achieved with while loops
num = 5
# selection:
if num < 100 :
print("The number is small")
else:
print ("The number is large")
# iteration:
while num < 10:
num = num + 1
print(num)
Lessons that discuss this:
- Lesson 3
Truth Tables:
Tables used to organize different possible combinations and whether they would be true or not based on the given parameters:
*Note: Binary can be used to represent T of F as well -- 0 is F and 1 is T
- AND truth tables: Both A AND B must be true for the overall operation to be true
A | B | Outcome |
---|---|---|
F | F | F |
F | T | F |
T | F | F |
T | T | T |
- OR truth tables: Either A OR B must be true for the overall operation to be true
A | B | Outcome |
---|---|---|
F | F | F |
F | T | T |
T | F | T |
T | T | T |
- XOR truth tables: Either A OR B must be true for the overall operation to be true, except if both are true then the overall outcome is F again
A | B | Outcome |
---|---|---|
F | F | F |
F | T | T |
T | F | T |
T | T | F |
Lessons that discuss this:
- Mr. Mort's lesson.. Week 2
Characters
Not talked about yet
A letter.. Python does not have a separate data type for characters, so single letters will still be considered a string (or a variable if its used for that)
Strings:
A string is a type of value, that includes text. Strings are usually denoted by surrounding the text in quotation marks. Even numbers can be classified as strings if they're put in quotation marks
string = "hello"
len("supercalifragilisticexpialidocious") #this word has 34 characters, so the function should print 34
string1 = "book"
string2 = "case"