Variables Notes Section 1-2
Lesson on variables from Collegeboard
- Variables
- Do's and Don'ts
- Types
- Assignments
- Data Abstraction
- Lists and Strings
- Mangaing Complexity
- Homework
num1 = 5
num2 = 9
num1 = num2
print(num1)
print(num2)
num1 = 15
num2 = 25
num3 = 42
num2 = num3
num3 = num1
num1 = num2
print(num1)
print(num2)
print(num3)
num2 += num1
print(num1)
print(num2)
print(str(num1)+ str(num2))
print(num1 + num2)
Lists and Strings
- A list is a sequence of elements
- An element is an individual value that is assignmed to a unique indec
- An index is a way to reference elements in a list or string through natural numbers
- A String is an ordered sequence of characters
- Indexes start at 1, are whole numbers, and cannot be negative
color1="green"
color2="red"
color3="pink"
color4="purple"
color5="blue"
color6="brown"
print(color1)
print(color2)
print(color3)
print(color4)
print(color5)
print(color6)
colors = ["green", "red", "pink", "purple", "blue", "brown"]
for color in colors:
print(color)
Q_Bank = [
"Dynamic code is code that has inputs and outputs that can change?",
"What is the keyword for defining a function in Python?",
"In Jupyter Notebooks the Input is in line with the Output",
"What is grouping often used commands called?",
]
Ans = [
"true",
"def()",
"false",
"procedural abstraction",
]
n = len(Q_Bank)
for question in Q_Bank:
n = n-1
print(Q_Bank[n])
rsp = input(Q_Bank[n])
if rsp.strip().lower() == Ans[n]:
print("Your answer " + str(rsp)+" is the correct correct")
else:
print("Your answer " + str(rsp) + " doesn't equal the correct answer/s which is " + str(Ans[n]))