Unit 3.1 and 3.2
3.1 Variables and Assignments
- Variables are abstractions within programs which represent a value
- Values can be individual data points or a list/collection that contains many data values
- Types of data: numbers, Booleans (T/F), lists, and string
- can be achieved in both python and javascript
3.2 Data Abstraction
- Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation
data abstractions manage complexity in programs by giving a collection of data a name without refrencing the specific elements of the representation
- Data Abstraction makes it easier to implement, develop and maintain code
- The use of lists allows for multiple related values to be treated as a single value
- In AP exam the index values for lists start rom 1 and not 0 like in python.
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 range (len(data)):
if data[i] > max_valid:
print(data[i],i)
elif data[i] < min_valid:
print(data[i], i)
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 = input("What album do you want")
song = input("What song do you want")
song_name = albums[int(album)-1][3][int(song)-1][1]
print(f"Now playing '{song_name}'")