Variables

  • Variables is an abtraction which holds a value
  • Organizes data by labeling with a name
  • Names help readibility and allow to understand what it represents

Do's and Don'ts

  • Keep them simple don't make them too complex
  • Seperare words with capital letters for readibility
  • Make them not too generic to allow understandabililty
  • No spaces
  • No dashes and numbers

Types

  • Integer: Number
  • String: words/charectors
  • Boolean: True/False
  • List can also be stored in variables to allow values to be retrieved and changed easily

Assignments

Used to change the values that are being represented by a variable

  • = Assigns value to the operand
  • += Adds right to left
  • -= Subtracts left from right
  • *= multiplies right with left
  • /= Divided left with right
  • **= Raised left to the right power
num1 = 5
num2 = 9
num1 = num2

print(num1)
print(num2)
9
9
num1 = 15
num2 = 25
num3 = 42
num2 = num3
num3 = num1
num1 = num2

print(num1)
print(num2)
print(num3)
42
42
15
num2 += num1
print(num1)
print(num2)

print(str(num1)+ str(num2))
print(num1 + num2)
42
84
4284
126

Data Abstraction

  • Used to represent data usefully, takes away things that aren't usefull at the moment
  • Done through variables and lists (mostly)
  • Seperates abstract properties and concrete properties

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

Mangaing Complexity

  • Data abstraction helps mangae complexity in programs by assigning a collection of data name without refrencing specific details of the represenation
  • Using data abrastraction can be used in a program that can be used to make a program that is easier to develop and maintain
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)
green
red
pink
purple
blue
brown
green
red
pink
purple
blue
brown

Homework

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]))
What is grouping often used commands called?
Your answer false doesn't equal the correct answer/s which is procedural abstraction
In Jupyter Notebooks the Input is in line with the Output
Your answer false is the correct correct
What is the keyword for defining a function in Python?
Your answer flase doesn't equal the correct answer/s which is def()
Dynamic code is code that has inputs and outputs that can change?
Your answer false doesn't equal the correct answer/s which is true