Homework Hacks 3.1
Homework Hacks 3.1
#Popcorn Hack #1
group_one = "Kiruthic"
GroupOne = "Anvay"
groupOne = "Yuva"
GROUPONE = "Pranav"
groupone = "Rayhaan"
print(group_one, GroupOne, groupOne, GROUPONE, groupone)
Kiruthic Anvay Yuva Pranav Rayhaan
// Popcorn Hack #2
fruit_info = [
{"name": "Apple", "color": "Red", "quantity": 5},
{"name": "Pineapple", "color": "Yellow", "quantity": 2},
{"name": "Mango", "color": "Orange", "quantity": 7},
{"name": "Banana", "color": "Yellow", "quantity": 10},
{"name": "Grapes", "color": "Purple", "quantity": 15}
]
print("Concatenation")
for fruit in fruit_info:
print("Example: I have " + str(fruit["quantity"]) + " " + fruit["name"] + "s, and they are " + fruit["color"] + ".")
print()
print("F-strings")
for fruit in fruit_info:
print(f"Example: I have {fruit['quantity']} {fruit['name']}s, and they are {fruit['color']}.")
print()
print("Separate the variable in the print statement")
for fruit in fruit_info:
print("Example: I have", fruit["quantity"], fruit["name"] + "s,", "and they are", fruit["color"] + ".")
Concatenation
Example: I have 5 Apples, and they are Red.
Example: I have 2 Pineapples, and they are Yellow.
Example: I have 7 Mangos, and they are Orange.
Example: I have 10 Bananas, and they are Yellow.
Example: I have 15 Grapess, and they are Purple.
F-strings
Example: I have 5 Apples, and they are Red.
Example: I have 2 Pineapples, and they are Yellow.
Example: I have 7 Mangos, and they are Orange.
Example: I have 10 Bananas, and they are Yellow.
Example: I have 15 Grapess, and they are Purple.
Separate the variable in the print statement
Example: I have 5 Apples, and they are Red.
Example: I have 2 Pineapples, and they are Yellow.
Example: I have 7 Mangos, and they are Orange.
Example: I have 10 Bananas, and they are Yellow.
Example: I have 15 Grapess, and they are Purple.
// Popcorn Hack #3
const car = {
make: "Toyota",
model: "Corolla",
color: "White",
year: 2020
};
console.log("Initial car details:", car);
car.color = "Red";
car.year = 2021;
console.log("Updated car details:", car);
Cell In[44], line 1
// Popcorn Hack #3
^
SyntaxError: invalid syntax
// Popcorn Hack #4
const Array = ["Hello, World!", 3.15];
// Homework Hack #1
const computerName = "Dell XPS 13";
let computerColor = "Silver";
let computerType = "Laptop";
console.log("Computer Name:", computerName);
console.log("Computer Color:", computerColor);
console.log("Computer Type:", computerType);
function describeComputer(name, color, type) {
return `The ${name} is ${color} and is a ${type}.`;
}
console.log(describeComputer(computerName, computerColor, computerType));
Cell In[45], line 1
// Homework Hack #1
^
SyntaxError: invalid syntax
#Homework Hack #2
grade1 = 85
grade2 = 90
grade3 = 95
grade4 = 92
grade5 = 88
total_grades = grade1 + grade2 + grade3 + grade4 + grade5
average_grade = total_grades / 5
student_info = ["Pranav Santhosh", 16, average_grade]
print("Grades: ", grade1, grade2, grade3, grade4, grade5)
print("Total Grades: ", total_grades)
print("Average Grade: ", average_grade)
print("Student Info: Name:", student_info[0], ", Age:", student_info[1], ", Average Grade:", student_info[2])
Grades: 85 90 95 92 88
Total Grades: 450
Average Grade: 90.0
Student Info: Name: Pranav Santhosh , Age: 16 , Average Grade: 90.0