Variables

  • Represent a value with a variable: strings, lists, booleans, numbers
  • Deetermine the value of a variable as a result of an assignment

Python

Defining Variables

  • Variable name "one word"
  • Variabels can be numbers, string, lists, or boolean
  • Use equal (=) sign to define
  • Strings have quotations "" around it
  • Functions and conditiosn with variables, including print()

Nathematical Expressions

  • Mathmatical expresions can be preformed on the variable that is numerical value

Functions on Lists

  • Functions can be preformed on lists, such as append()

Dictionaries

  • Defined using curly brackets and equal sign
  • Keys and values

Interchanging Variables

  • INterchange vriables using temporary variable

Floats

  • Define variabvles using float dta types isntead of just integer

Even Function

  • Define function with def and colon
  • Parenthesis () after function name

Variables and Assigment in JavaScript

Number

  • Define variable, e.g. x=1

Boolean

  • True and False

Strings

  • Words

List

  • sequence of several variables, grouped together under a single name

Data Abstraction in Python

Data Abstraction

  • Provides a separation between the batraqct properties of a data type and the concrete details of its represenation
  • Manage complexiity in programs by giving a collectioin of data a name withut referencing specific elements of the representation
  • Makes it easier to implement, develop, and maintain code
  • Us eof listws allows for mutipel related values to be treated as a single vaaaue
  • On AP exams index values for lists start from 1, not 0 like in Python

Python

Using simple lists and wokring with vairables

  • Lists can organize, maintain and develop related data
  • e.g. A shopping cart with multiple items, instead of having each item in the cart be its own variable, all the data can be under one variable. If the shopping cart changed, you can edit the list instead of deleting the entire variable

Breaking lists into more lists

  • List of data can be split even more
  • e.g. Separate a list of dta into 2 new lists
  • Organize dta recieved from APi's an othe rresources

Organising different items in the lists

  • Indidivudal elements can be called, sparated,and organised using for loops

Splitting and joining lists and data inside them

  • split() - splits a string itmo a list, where you can speciy the separtator, default separator is any whitespace
  • join() - takes all items in iterable and joins them into one string, which must be specified as the separator

Data Abstraction in JavaScript

  • Delare a function, inout and store data, and dsiplay it

Challenge and Homework

data = [104, 101, 4, 105, 308, 103, 5, 107,
        100, 306, 106, 102, 108]    # list of the different numerical values
min_valid = 100  # minimum value
max_valid = 200  # maximum value

for i in data:
    if i >= min_valid and i<= max_valid:
        print(str(i) + " is within the range. It's index value is " + str(data.index(i)) + ".")
    else:
        print(str(i) + " is within the range. It's index value is " + str(data.index(i)) + ".")
104 is within the range. It's index value is 0.
101 is within the range. It's index value is 1.
4 is within the range. It's index value is 2.
105 is within the range. It's index value is 3.
308 is within the range. It's index value is 4.
103 is within the range. It's index value is 5.
5 is within the range. It's index value is 6.
107 is within the range. It's index value is 7.
100 is within the range. It's index value is 8.
306 is within the range. It's index value is 9.
106 is within the range. It's index value is 10.
102 is within the range. It's index value is 11.
108 is within the range. It's index value is 12.
albums = [
    ("Welcome to my Nightmare", "Alice Cooper", 1975,   # First album list
     [
         (1, "Welcome to my Nightmare"),
         (2, "Devil's Food"),
         (3, "The Black Widow"),
         (4, "Some Folks"),
         (5, "Only Women Bleed"),
     ]
     ),
    ("Bad Company", "Bad Company", 1974,   # Second album list
     [
         (1, "Can't Get Enough"),
         (2, "Rock Steady"),
         (3, "Ready for Love"),
         (4, "Don't Let Me Down"),
         (5, "Bad Company"),
         (6, "The Way I Choose"),
         (7, "Movin' On"),
         (8, "Seagull"),
     ]
     ),
    ("Nightflight", "Budgie", 1981,
     [
         (1, "I Turned to Stone"),
         (2, "Keeping a Rendezvous"),
         (3, "Reaper of the Glory"),
         (4, "She Used Me Up"),
     ]
     ),
    ("More Mayhem", "Imelda May", 2011,
     [
         (1, "Pulling the Rug"),
         (2, "Psycho"),
         (3, "Mayhem"),
         (4, "Kentish Town Waltz"),
     ]
     ),
]


album_num = int(input("Choose an album 1-4:"))
if album_num == 2:
    song_num = int(input("Choose a song 1-8:"))
else:
    song_num = int(input("Choose a song 1-4:"))

print("Playing " + str(albums[album_num-1][3][song_num-1][1]) + " from Album " + str(albums[album_num-1][0]) + " by Artist " + str(albums[album_num-1][1]) + " in " + str(albums[album_num-1][2]))
Playing Ready for Love from Album Bad Company by Artist Bad Company in 1974