3.1-3.2- Variables and Assignments/Data Abstraction

Notes

  • A varaible is a abstraction made inside a program that holds a value
  • Make sure varaibles are correct
  • Boolean are true or false statements
  • Integers are numbers
  • Lists and dictionary are letters
  • A string can represent someones phone number
  • A varible is updated by making the varaible equal to something else in a new line
  • Sudo code is where syntax doesn't matter
  • Python the assignemnt oporator is =
  • Quotes means it is a string
  • Square brackets are a list
  • Javascript in this line of code we are trying to assign the buttons a variable
  • Strings are a series of characters
  • Lists are sequences of elements where each element in the list is a variable. An order to them
  • Using negative numbers you and start the list from the end
  • Data abstraction simplies code
  • Lists means that the user doesn't need to know the data
  • Printing a list of variables can be used with individual variables and the print() code. This is inefficient. You can use a single variable such as score = []. Then print it with print()

Hacks

Hack 1

  • An assignment operator is the transition character of a variable. = for python for example
  • Collegeboard pseudocode uses an arrow <--- to assign values to variables
  • If a variable, x, is initially given a value of 15 and ;ater on changed to 22 it would display 22 because it was changed from 15.

Hack 2

  • A list is a series of varaibles that are listed then printed in one
  • An element is the characters isside a string
  • An easy way to reference elementing in a list or string is to use a print command but also list the number of that varable in the list. If it is the thrid item in the list you can put 2 or negative to if theres four items in the list
  • An example of a string is name = "jake"
name = "Jake"
favfood = ["burger", "steak", "burrito"]
print(name, favfood)
Jake ['burger', 'steak', 'burrito']
food = ["burger", "steak", "burrito"]
print(food[2])
print(food[-1])
burrito
burrito

Hack 3

num1=input("Input a number. ")
num2=input("Input a number. ")
num3=input("Input a number. ")
add=input("How much would you like to add? ")

# Add code in the space below

numlist = [int(num1), int(num2), int(num3)]

# The following is the code that adds the inputted addend to the other numbers. It is hidden from the user.

for i in numlist:
    numlist[i -1] += int(add)

print(numlist)

Hack 4

Python Quiz

  • Complexity
  • Abstraction
  • []
food = ["pizza", "hot dog", "sushi", "strawberry", "sandwich"]
print(food)
['pizza', 'hot dog', 'sushi', 'strawberry', 'sandwich']
  • Lists are better for a program than writing out the code because it makes the code more simple. It allows other programers to understand the code better and make edits easier.
team1 = "Bengals"
team2 = "Saints"
team3 = "Texans"
team4 = "Cowboys"
print(team1, team2, team3, team4)
Bengals Saints Texans Cowboys
team = ["Bengals", "Saint", "Texans", "Cowboys"]
print(team)
['Bengals', 'Saint', 'Texans', 'Cowboys']

Vocab

  • Variable: a code which maps source symbols to a variable number of bits
  • Strings: a sequence of characters terminated with a null characte
  • Dictionary: unordered collection that contains key:value pairs separated by commas inside curly brackets
  • Lists: a sequence of several variables, grouped together under a single name
  • Data Types: a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.
  • Data Abstraction: the reduction of a particular body of data to a simplified representation of the whole
x = 10
y = 11
Students = {
    'Names': ['Jake','Brady', 'John'],
    'GPA': [4.00, 3.40, 1.8],
    'Sports': ['Foootball','Baseball', 'None'],
}
print(Students['GPA'][1])
print(Students['Names'][2])
3.4
John
string1 = "Hello"
string2 = "World"
print(string1, string2)
print(string2, string1)
Hello World
World Hello