3.1, 3.2, 3.5, 3.6, and 3.7 Notes, Challange, and HW
The homework assignment and challenge in our lesson plan
Notes on 3.1 and 3.2
-
Key Details
- 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 (ie; numbers, Booleans (T/F), lists, and strings)
- Languages (Python and Javascript)
-
Transformations of languages to HTML
-
Elements are unique, individual values
- Lists are made up of elements
- Strings are made of repeating characters instead of elements
- Data abstraction uses a list by taking specific data elements from a list and organizing into a whole, less complex representation of the values such as a table in windows Excel which uses similar function
data = [104, 101, 4, 105, 308, 103, 5, 107,
100, 306, 106, 102, 108] # list of the different numerical values
for a in data:
if a > 100:
if a < 200:
ind = data.index(a)
print("the index of " + str(a) + " is at place " + str(ind + 1) + " out of 13 in the number list")
else:
continue
else:
continue
Homework/Hacks
The list given contains 4 album names - Welcome to my Nightmare, Bad Company, Nightflight, More Mayhem - and each album contains at least 4 songs within another list. Given this, write a block of code that enables users to input in integer values that correspond to the albums and songs - Welcome to my Nightmare is 1, Bad Company is 2, etc. - Then, a sentence is outputted that says Playing ___ based on which song was chosen using the numbers inputted by the user that corresponds to each song.
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("enter album selection")
song = input("enter song selection")
print("Now playing ~ " + albums[int(album) - 1][3][int(song) - 1][1])
Notes on 3.5, 3.6, and 3.7
-
Important vocab
- Boolean
- T/F statements.
- Boolean Operator
- Boolean operators produces booleans after it is used between two values.
- Relational Operators
- Relational Operators can work between any two values of the same type known as operands.
- consist of the operators ==, !=, >, <, >=, <=, each one working the same way that they work as one would expect.
-
Logical Operators
- These are operators that works on operand(s) to produce a single boolean result.
- Examples include and, or, not.
-
Algorithm
- A set of instructions that accomplish a task.
- Selection
- The process that determines which parts of an algoritm is being executed based on a condition that is true or false.
- Boolean
school = input("What high school do you go to? EX. Forgotten High School");
if school == ("Del Norte High School"):
print("You are at the 3rd best school in San Diego County, 17th best school in the state!");
else:
print("Unfortunate");
if school == ("Mount Carmel High School"):
print("You are at the worst School in the state... Congrats?");
else:
print("Unfortunate");
Homework for 3.5, 3.6, and 3.7
our homework we have decided for a decimal number to binary converter. You must use conditional statements within your code and have a input box for where the decimal number will go. This will give you a 2.7 out of 3 and you may add anything else to the code to get above a 2.7.
Below is an example of decimal number to binary converter which you can use as a starting template.
def DecimalToBinary(num):
strs = ""
while num:
# if (num & 1) = 1
if (num & 1):
strs += "1"
# if (num & 1) = 0
else:
strs += "0"
# right shift by 1
num >>= 1
return strs
# function to reverse the string
def reverse(strs):
print(strs[::-1])
# Driver Code
num = 67
print("Binary of num 67 is:", end=" ")
reverse(DecimalToBinary(num))