Skip to the content.

3.8 hacks

POPCORN HACKZ

3.8.1 popcorn hack #1

#start at 0
counter = 0
#untill it reaches 5 keep writing hello
while counter < 5:
    print("hello")
    counter += 1
hello
hello
hello
hello
hello

3.8.2 popcorn hack #2

#Define names
first_name = "Nora"
middle_name = "Emelya"
last_name = "Ahadian"

for _ in range(4): #repeat 4 times
    print(first_name)  # Print first name 1 time
    for _ in range(2):
        print(middle_name)  # Print middle 2 times
    for _ in range(3):
        print(last_name)  # Print last name 3 times

Nora
Emelya
Emelya
Ahadian
Ahadian
Ahadian
Nora
Emelya
Emelya
Ahadian
Ahadian
Ahadian
Nora
Emelya
Emelya
Ahadian
Ahadian
Ahadian
Nora
Emelya
Emelya
Ahadian
Ahadian
Ahadian

3.8.3 popcorn hack #3

#Define name
name = "Nora"

#tell the code to spell it out by letter
for letter in name:
    print(letter)
N
o
r
a

3.8.4 popcorn hack #4

%%js

//define items for dictionary
const student_info = {
    'nora': 15,
    'joanna': 17,
    'maryam': 17,
    'kushi': 15
};

//Log the info as items
console.log(Object.entries(student_info));

//Iterate over key-value pairs with for loop!
for (let [name, age] of Object.entries(student_info)) {
    console.log(name, " is ", age);
}
<IPython.core.display.Javascript object>

3.8.5 BIG HACKZ

hack 1

# Correct password
password = "PaaSword123"

while True:
    # Prompt user for password
    user_input = input("Enter password: ")

    # Check if password is correct
    if user_input == password:
        print("Password is correct.")
    else:
        print("Incorrect password. Please try again.")

Incorrect password. Please try again.
Password is correct.

Hack 2

#Prompt user for their name
name = input("Please enter your name: ")

#Print each letter
for letter in name:
    print(letter)
n
o
r
a

Hack 3

# make list of fruits
fruits = ['Apple', 'Banana', 'Orange', 'Mango', 'Grapes', 'Pineapple', 'Strawberry']

# Loop through the list and print each fruit
for fruits in fruits:
    print(fruits)
Apple
Banana
Orange
Mango
Grapes
Pineapple
Strawberry