Unit 3 Vocabulary (Definitions + Examples)
Home | API | Notes |
Variables: A variable is a named container that stores a value that can be changed or updated.
X = 5
print(X)
Data Types: Different types of data such as numbers, strings, booleans, and objects that can be stored in variables.
X = "hello"
print(X)
Assignment Operators: Operators that are used to assign a value to a variable.
three = 3
print(three)
Managing Complexity with Variables: Lists, 2D Lists, Dictionaries, Class: Ways of organizing data in a more complex structure.
MyList = [1,2,3,4,5]
print(MyList)
Algorithms: A set of instructions for solving a problem.
Example: To find the largest number in a list, you could use a sorting algorithm.
Sequence, Selection, Iteration: Three types of control flow structures in programming.
Example: For a sequence, you could create a loop that prints out each number from 1 to 10.
Expressions, Comparison Operators, Booleans Expressions and Selection, Booleans Expressions and Iteration, Truth Tables: Expressions are used to evaluate values and comparison operators are used to compare values.
if (5 > 3) is True:
print("True")
else:
print("False")
Characters: Individual letters, numbers, and symbols
Characters = "H"
print(Characters)
Strings: A a combination of characters Length: The number of characters in a string Concatenation: A combination of strings together
Strings = "Hello World"
Strings2 = "World Hello"
print(Strings)
print(len(Strings))
print(Strings, Strings2)
Upper and Lower: Functions for changing the case of characters
Traversing Strings: Looping over each character in a string.
If, Elif, Else conditionals; Nested Selection Statements: Control statements that allow you to execute code based on certain conditions.
x = 5
if x > 0:
print("x is greater than 0")
elif x == 0:
print("x is equal to 0")
else:
print("x is less than 0")
Python For, While loops with Range, with List: Types of loops that allow you to iterate over a range of numbers or a list of items.
import random
x = random.randint(0,10)
for x in range(0, 10):
print(x)
Combining loops with conditionals to Break, Continue: Control statements that allow you to break out of a loop or skip an iteration.
x = 2
while x < 10:
if x == 5:
break
x += 1
print(x)
Procedural Abstraction: A process used to simplify complex tasks by breaking them down into smaller, easier-to-manage tasks.
Python Def Procedures: A method used to define a set of instructions to be executed when a certain procedure is called.
Parameters: Arguments that are passed to a procedure when it is called.
Return Values: A value that is returned after a procedure has been executed.
Selection: Selection is a type of control flow that allows for the execution of certain code based on certain conditions.
firstNum = int(input("Input your first number."))
secondNum = int(input("Input your second number."))
conditional = input("AND, OR, XOR?").lower()
if conditional == "and":
print("Selection:" , "AND", firstNum, "&", secondNum, "=", firstNum & secondNum)
elif conditional =="or":
print("Selection:" , "OR ", firstNum, "|", secondNum, "=", firstNum | secondNum)
elif conditional =="xor":
print("Selection:" , "XOR", firstNum, "^", secondNum, "=", firstNum ^ secondNum)
else:
print("Error")
Lists: Lists are data structures used to store multiple values in one variable.
Iteration: Iteration is a type of control flow that allows for the execution of certain code multiple times.
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
name = "Ethan Tran"
print("name", name, type(name))
print()
# variable of type integer
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
age = 15
print("age", age, type(age))
print()
# variable of type float
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
score = 100.0
print("score", score, type(score))
print()
# variable of type list (many values in one variable)
print("What is variable name/key?", "value?", "type?", "primitive or collection?")
print("What is different about the list output?")
langs = ["Python", "JavaScript", "Java" , "Bash" , "C" , "R"]
print("langs", langs, type(langs), "length", len(langs))
print("- langs[0]", langs[0], type(langs[0]))
print()
# variable of type dictionary (a group of keys and values)
print("What is the variable name/key?", "value?", "type?", "primitive or collection, why?")
print("What is different about the dictionary output?")
person = {
"name": name,
"age": age,
"score": score,
"langs": langs,
}
print("person", person, type(person), "length", len(person))
print('- person["name"]', person["name"], type(person["name"]))
Logical Operator: A logical operator is a type of operator in computer science that performs a logical operation, such as a comparison or a boolean operation, on two or more values or variables. Examples of logical operators include AND, OR, NOT, XOR, and NAND.
Tru = True
equals = "="
opposite = not(Tru)
print(opposite)
fun = "fun"
awesome = fun
if fun and awesome == "fun":
print("AND")
else:
print("NOT AND")
fun = "fun"
awesome = fun
if fun and awesome == "fun":
print("AND")
else:
print("NOT AND")
import random
numList = ["1", "2", "3", "4", "5"]
ranNum = random.randrange(len(numList))
print(ranNum)
if ranNum == 2 or ranNum == 5:
print("OR")
else:
print("NOT OR")