Skip to the content.
Home Accounts Setup Verify Play Hacks

Gaheera Babbar P4 Popcorn Hacks 3.1 Variables

3.1 Lesson Popcorn and Homework Hacks

Python

Gaheera Babbar P4 Popcorn Hacks 3.1

# Python Popcorn Hack 1: Team Variables
seat_one = "Gaheera"
seat_two = "Rhea"
seat_three = "Hannah"
seat_four = "Rowan"
print(seat_one, seat_two, seat_three, seat_four)
Gaheera Rhea Hannah Rowan
# Python Popcorn Hack 2: Fruit Dictionary
fruits = {
    "apple": {
        "color": "red",
        "taste": "sweet",
        "season": "fall",
        "description": "Apples are crunchy and sweet. They are often used in pies and desserts."
    },
    "banana": {
        "color": "yellow",
        "taste": "sweet",
        "season": "year-round",
        "description": "Bananas are soft and sweet. They are great as a snack or in banana bread and smoothies. They are excellent sources of potassium."
    },
    "orange": {
        "color": "orange",
        "taste": "citrus",
        "season": "winter",
        "description": "Oranges are juicy and tangy. They are full of vitamin C and perfect for juice."
    }
}
print(fruits["banana"]["description"])
Bananas are soft and sweet. They are great as a snack or in banana bread and smoothies. They are excellent sources of potassium.
%%js
//Popcorn Hack 3: Define variables automatically using let and const, write console.log() statements and demonstrate knowledge of accessing the console correctly, and short function that correctly calls each variable and string them together to make a sentence.
// Automatically define variables
const name = "Gaheera";            // Using const because the name will not change
let age = 17;                   // Using let since the age can change
const favoriteFruit = "watermelon";  // This will remain constant
let school = "Del Norte High School";            // School might change later

// Demonstrate accessing variables via console.log()
console.log("Name:", name);
console.log("Age:", age);
console.log("Favorite fruit:", favoriteFruit);
console.log("school:", school);

// Short function that combines variables into a sentence
function createSentence() {
    return `Hi, my name is ${name}. I am ${age} years old, and I love ${favoriteFruit}. I currently go to ${school}.`;
}

// Call the function and log the sentence to the console
console.log(createSentence());
// Changing values of the variables declared with 'let'
age = 18;

// Call the function again with updated values
console.log(createSentence());

<IPython.core.display.Javascript object>
%%js
// Popcorn Hack 4: Create your own array using two or more diffrent data types we throughout the lesson!

let classmates = ["rowan", "gaheera", "rhea", "hannah"];//creates an array of strings (classmates) and logs it to the console
console.log("Array: ", classmates);
element.append("Array: " + classmates.join(", "));

let data = ["integer", "string", "boolean", "float"];
console.log("Array: ", data);
element.append(" Array: " + data.join(", "));
<IPython.core.display.Javascript object>
%%js 
// Step 1: Define scores for a student
let score1 = 75;
let score2 = 90;
let score3 = 78;
let score4 = 82;
let score5 = 98;

// Step 2: Calculate total score and average
let totalScore = score1 + score2 + score3 + score4 + score5;
let numberOfScores = 5;  // Number of subjects/scores
let averageGrade = totalScore / numberOfScores;

// Step 3: Define student information
const studentName = "Gaheera";
const studentAge = 17;

// Step 4: Create an array to store student info and average grade
let studentInfo = [studentName, studentAge, averageGrade];

// Display student details in the document body
document.body.innerHTML = `
  <h3>Student Info</h3>
  <p>Student Name: ${studentInfo[0]}</p>
  <p>Student Age: ${studentInfo[1]}</p>
  <p>Average Grade: ${studentInfo[2]}</p>
`;
<IPython.core.display.Javascript object>