Variables

  • an abstraction within a program that can hold a value
  • helps keep data simple to understand in code
  • consists of 3 parts: name, value and type

Naming variables

  • keep it simple yet not vague
  • differentiate variables with capitals
  • don't have spaces or dashes

Types of data

  • Integer - a number
  • Text/string - words or characters
  • Boolean - true or false
  • Array - a list of values

Assignments

  • = operator assigns left side to right
  • += operator adds the value on the right to the left
  • -= operator subtracts the value on the right from the left
  • *= operator multiplies the value on the right with the left
  • /= operator divides the left value by the right
  • **= operator raises the left value to the power of the right value

Data Abstraction

  • Method used in coding to represent data in a useful form, by taking away data which isn’t useful
  • Variables and lists are main tools in data abstraction
  • Data abstractions help manage complexity in programs by giving a collection of data a name without referencing the specific details of the representation
  • Developing a data abstraction to use in a program can result in a program that is easier to develop and maintain

Lists and Strings

  • Lists are ordered sequences of elements
  • Elements are individual values or variables
  • Strings are ordered sequences of characters.
  • There are three different types of list operators in data abstraction:
  • Assigning values in a list to certain indices
  • Creating an empty list and assigning it to a variable
  • Assigning a copy of one list to another

Managing Complexity

  • Making code simpler to read
  • Bundling multiple variables into a list

How do lists help manage complexity

  • Don’t need as many variables
  • Can easily change total number of variables
  • Can apply same mathematical computation to the whole list rather than going one by one

Homework

name=input("What is your name?")
print("Welcome", name)
testScores = [98.1, 90.1, 86.4, 77.3, 95.9, 93.3]
print("Your test scores so far:\n")
for x in testScores:
  print(x) 

print("")
  
meanScores = sum(testScores)
testAverage = meanScores // (len(testScores))
print("Your test average is:")
print(testAverage)
Welcome Aniket
Your test scores so far:

98.1
90.1
86.4
77.3
95.9
93.3

Your test average is:
90.0