3.1 HACKS
Student led teaching on Abstraction. Teaching how various data types can use abstraction for computational efficiency.
PYTHON POPCORN HACK 1:
# Strings
daddy = "Thomas Bao"
classmate2 = "Collin Ge"
classmate3 = "Aarush Gota"
me = "Ian Manangan"
# Printing out team members
print("Team Leader:", daddy)
print("Classmate:", classmate2)
print("Classmate:", classmate3)
print("Me:", me)
Team Leader: Thomas Bao
Classmate: Collin Ge
Classmate: Aarush Gota
Me: Ian Manangan
PYTHON POPCORN HACK 2:
# Dictionary for fruits
fruits = {
"red": "apple",
"orange": "orange",
"yellow": "banana"
}
# Output
print(fruits)
print(fruits["red"])
print(fruits["orange"])
print(fruits["yellow"])
{'red': 'apple', 'orange': 'orange', 'yellow': 'banana'}
apple
orange
banana
PYTHON HOMEWORK HACK 1:
# Hack #2: Average Grade Calculator using integers, addition, and lists
# Step 1: Define the student's information and their grades
# Using variables to store scores
student_name = "Ian Manangan"
student_age = 16
math_score = 85
science_score = 90
history_score = 88
english_score = 92
# Step 2: Add the grades together and calculate the average
# Calculate the total score by adding individual scores
total_score = math_score + science_score + history_score + english_score
# Number of subjects
number_of_subjects = 4
# Calculate the average grade
average_grade = total_score / number_of_subjects
# Step 3: Create a list to store student info (name, age, average grade)
# Storing the information as a list in Python
student_info = [student_name, student_age, average_grade]
# Step 4: Print the result
# Print student info and their average grade
print("Student Information:", student_info)
print(f"Student Name: {student_info[0]}")
print(f"Student Age: {student_info[1]}")
print(f"Average Grade: {student_info[2]:.2f}") # Formatting the average to 2 decimal places
Student Information: ['Ian Manangan', 16, 88.75]
Student Name: Ian Manangan
Student Age: 16
Average Grade: 88.75
JAVASCRIPT POPCORN HACK 1:
// Declare an object using 'const'
const person = {
firstName: "Ian",
lastName: "Manangan",
age: 1000000
};
// Log the original object
console.log("Original object:", person);
// Update properties of the object
person.firstName = "Taylor"; // Changing first name
person.age = 26; // Updating age
// Add a new property
person.city = "New York";
// Log the updated object
console.log("Updated object:", person);
JAVASCRIPT HOMEWORK HACK 1:
// Hack #1: Defining variables automatically using let and const
// Declare a variable using 'let' (can be reassigned)
let myName = "Ian";
// Declare a variable using 'const' (cannot be reassigned)
const greeting = "Hello";
// Another 'let' variable to store a place
let place = "world";
// This function will call all the variables and string them together into a sentence
function createGreeting() {
// Concatenate the variables to form a sentence
const sentence = greeting + ", " + myName + "! Welcome to the " + place + ".";
// Log the sentence to the console
console.log(sentence);
}
// Calling the function to see the result in the console
createGreeting();
// View individual values of each variable
console.log("My Name:", myName);
console.log("Greeting:", greeting);
console.log("Place:", place);