Rhea Rajashekhar P4 Popcorn Hacks 3.1 variables
# 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)
# 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"])
# Python Popcorn Hack 3: Student Scores
scores = [75, 90, 78, 82, 98] # List of scores
total_score = sum(scores) # Calculate total score
average_grade = total_score / len(scores) # Calculate average
# Define student information
student_name = "Rhea"
student_age = 17
# Display student details
print(f"Student Name: {student_name}")
print(f"Student Age: {student_age}")
print(f"Average Grade: {average_grade:.2f}")
%% js
// Function to create a sentence
function createSentence() {
return `Hi, my name is ${name}. I am ${age} years old, and I love ${favoriteFruit}. I currently go to ${school}.`;
}
// Log the sentence to the console
console.log(createSentence());
// Changing values of the variables declared with 'let'
age = 18;
console.log(createSentence());
// Popcorn Hack 2: Student Scores
let scores = [75, 90, 78, 82, 98]; // Array of scores
let totalScore = scores.reduce((acc, score) => acc + score, 0); // Calculate total score
let averageGrade = totalScore / scores.length; // Calculate average
// Display student details in the document body
document.body.innerHTML = `
<h3>Student Info</h3>
<p>Student Name: ${name}</p>
<p>Student Age: ${age}</p>
<p>Average Grade: ${averageGrade.toFixed(2)}</p>
`;