Skip to the content.

3.5 Hacks and Homework

Completing the hacks and homework for lesson 3.5


3.5


Hack 1


Python


# Assigning integer `age`
age = 299139

# Assigning boolean `is_old`
is_old = age > 139913

# If the age is over 139913, the first code will be run. Otherwise, the second code will be run.
if is_old:
    print("How are you alive?")
else:
    print("Hi! You can be alive.")
How are you alive?


JavaScript


%%javascript

// Assigning integer `age`
let age = 299139;

// Assigning boolean `is_old`
let is_old = age > 139913;

// If the age is over 139913, the first code will be run. Otherwise, the second code will be run.
if (is_old) {
    console.log("How are you alive?");
} else {
    print("Hi! You can be alive.");
}
<IPython.core.display.Javascript object>


Hack 2


Python


# Assigning integer `height_inches`
height_inches = 75

# Average height is between 8 feet and 10 feet, exclusive
is_average_height = height_inches > 96 and height_inches < 120

# Non-average height is anywhere not in that range
is_not_average_height = not is_average_height

# If the height falls in the average range, first code will be run. Otherwise, second code will be run.
if is_average_height:
    print("Your height is average.")
elif is_not_average_height:
    print("You are too tall or too short.")
You are too tall or too short.


JavaScript


%%javascript

// Assigning integer `height_inches`
let height_inches = 75;

// Average height is between 8 feet and 10 feet, exclusive
let is_average_height = height_inches > 96 && height_inches < 120;

// Non-average height is anywhere not in that range
let is_not_average_height = !is_average_height;

// If the height falls in the average range, first code will be run. Otherwise, second code will be run.
if (is_average_height) {
    console.log("Your height is average.");
} else if (is_not_average_height){
    console.log("You are too tall or too short.");
}
<IPython.core.display.Javascript object>


Hack 3


Python


# Assigning integer `age`
age = 10

# Only children under the age of 16 may drive
can_drive = age < 16

# If age < 16, first string is printed. Otherwise, second string is printed.
print(can_drive if "You can drive!" else "No driving you old person.")
True


JavaScript


%%javascript

// Assigning integer `age``
let age = 10;

// Only children under the age of 16 may drive
let can_drive = age < 16;

// If age < 16, first string is printed. Otherwise, second string is printed.
console.log(can_drive ? "You can drive!" : "No driving you old person.");
<IPython.core.display.Javascript object>


Homework


A B Operator Result
True True And True
True False And False
False True And False
False False And False
True True Or True
True False Or True
False True Or True
False False Or False
True True Xor False
True False Xor True
False True Xor True
False False Xor False