First Group of 10-4
Popcorn Hacks
%%javascript
for (let i = 0; i < 10; i++) {
console.log(i);
}
vehicles = ['🚲', '🏍️', '🛴']
for vehicle in vehicles:
print(vehicle)
🚲
🏍️
number = 1
while number <= 10:
if number % 2 == 0:
print(number)
number += 1
2
4
6
8
10
import random
flip = ""
while flip != "heads":
flip = random.choice(["heads", "tails"])
print(f"Flipped: {flip}")
print("Landed on heads!")
Flipped: heads
Landed on heads!
tasks = [
"homework",
"water",
"eat dinner",
"eat breakfast",
"exercise"
]
# Function to display tasks with indices
def display_tasks():
print("Your To-Do List:")
for index in range(len(tasks)):
print(f"{index + 1}. {tasks[index]}") # Display task with its index
# Call the function
display_tasks()
Your To-Do List:
1. homework
2. water
3. eat dinner
4. eat breakfast
5. exercise
%%javascript
// List of tasks
const tasks = [
"homework",
"water",
"eat dinner",
"eat breakfast",
"exercise"
];
// Function to display tasks with indices
function displayTasks() {
console.log("Your To-Do List:");
for (let index = 0; index < tasks.length; index++) {
console.log(`${index + 1}. ${tasks[index]}`); // Display task with its index
}
}
// Call the function
displayTasks();
<IPython.core.display.Javascript object>
%%javascript
for (let i = 0; i < 10; i++) {
if (i === 5) {
break;
}
console.log(i);
}
<IPython.core.display.Javascript object>
for i in range (10):
if i == 5:
break
print(i)
0
1
2
3
4
Homework Hacks
animal = {'name': 'tiger', 'strength': 'strong', 'size': 'large'}
for key, value in animal.items():
print(key, ":", value)
name : tiger
strength : strong
size : large
%%js
animal = { 'name': 'tiger', 'strength': 'strong', 'size': 'large' }
for (const key in animal) {
console.log(key + ": " + animal[key]);
}
<IPython.core.display.Javascript object>
i = 1
while i < 51:
if i % 3 == 0:
if i % 5 == 0:
print("FizzBuzz")
elif i % 7 == 0:
print("Boom")
else:
print("Fizz")
elif i % 5 == 0:
if i % 3 == 0:
print("FizzBuzz")
else:
print("Buzz")
elif i % 7 == 0:
print("Boom")
else:
print(i)
i += 1
username = "john"
password = "tokyo"
wrong_counter = 3
while wrong_counter > 0:
user = input("Enter the username: ")
psd = input("Enter password: ")
if user != username or psd != password:
print("Failed Attempt")
print("Amount of times you have left:", wrong_counter - 1)
else:
print("Sucess")
wrong_counter -= 1
Failed Attempt
Amount of times you have left: 2
Failed Attempt
Amount of times you have left: 1
Failed Attempt
Amount of times you have left: 0
%%javascript
for (let i = 0; i < 10; i+= 2) {
if (i === 5) {
break;
}
console.log(i);
}
<IPython.core.display.Javascript object>
for i in range (10):
if i == 5:
continue
if i == 8:
break
print(i)
0
1
2
3
4
6
7
8
9