#3.6.1 POPCORN HACK 1
#use temp to check if it works!
temperature = 70
#hot day
if temperature >= 80:
print("It's a hot day")
#warm day
elif 60 <= temperature <= 79:
print("It's a warm day")
#cold day
else:
print("It's a cold day")
It's a warm day
Explanation:
I used elif to add another ‘else if’ stating that if it is between 60 and 79 degrees then it is a warm day
%%js
//3.6.2 POPCORN HACK 1
//plug in numbers to score to test outcomes
let score = 55;
if (score >= 60) {
console.log("You passed yahoo!");
}
//an an else to say that you failed
else (score >= 59){
console.log("uh oh you failed (stupid)")
}
<IPython.core.display.Javascript object>
Explanation:
I added an else to the condition where if the score is less then or equal to 59 then you failed (and your stupid)
#3.7.1 POPCORN HACK 1
weather = "sunny"
transportation = "available"
boots = "not present"
energy = "energized" #new condition
print("The weather is " + weather)
print("Your transportation is " + transportation)
print("Your boots are " + boots)
print("you are feeling " + energy)
if weather == "sunny":
if transportation == "available":
if boots == "present":
if energy == "energized":
print("You are ready to go hiking!")
else:
print("You need to find your boots first.")
else:
print("You need to arrange transportation.")
else:
print("It's not good weather for hiking.")
else:
print("you dont have enough energy") #added conditional based on your energy level
The weather is sunny
Your transportation is available
Your boots are not present
you are feeling energized
You need to arrange transportation.
Explanation:
I added another conditional that checks your energy levels. If you are energized you can go hiking, if your tired you need to rest
%%js
//3.7.2 POPCORN HACK 1
let weather = "sunny";
let transportation = "available";
let boots = "not present";
let energy = "energized"; //new condition
console.log("The weather is " + weather);
console.log("Your transportation is " + transportation);
console.log("Your boots are " + boots);
console.log("you are feeling " + energy)
if (weather === "sunny") {
if (transportation === "available") {
if (boots === "present") {
if (energy == "energized"){
console.log("you are ready to go hiking!")
} else {
console.log("you are too tired to go hiking")
}
} else {
console.log("You need to find your boots first.");
}
} else {
console.log("You need to arrange transportation.");
}
} else {
console.log("It's not good weather for hiking.");
}
<IPython.core.display.Javascript object>
Explanation:
I used javascript formating to indent the else statments. Then I added in my new energy conditional into the variables and in the function
BIG HACKS 3.6.3
#HACK 1
#if its divisible by 2 then it is even if not then it is odd
def check_odd_even(number):
if number % 2 == 0:
return "Even"
else:
return "Odd"
print(check_odd_even(3)) # check odd number
print(check_odd_even(12)) # check even number
Odd
Even
#HACK 2
#Check if the year is divisible by 4 but not by 100, or divisible by 400
def is_leap_year(year):
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
return "Leap Year"
else:
return "Not a Leap Year"
# Testing the function with different years
print(is_leap_year(2000)) # check leap year
print(is_leap_year(1900)) # check not leap Year
Leap Year
Not a Leap Year
#HACK 3
#hot day
if temperature >= 85:
print("It's a hot day")
#warm day
elif 60 <= temperature <= 70:
print("It's a warm day")
#cold day
else:
print("It's a cold day")
#plug in a tempreture to check if it works!
temperature = 60
It's a warm day
BIG HACKS 3.6.4
%%js
//HACK 1
function checkVotingEligibility(age) {
// Check if the age is 18 or older
if (age >= 18) {
return "You are eligible to vote";
} else {
return "You are not eligible to vote";
}
}
// Testing the function with different age values
console.log(checkVotingEligibility(15)); // check eligible to vote
console.log(checkVotingEligibility(18)); // check eligible to vote
<IPython.core.display.Javascript object>
%%js
//HACK 2
function getGrade(score) {
// determine letter grade based on inequalities
if (score >= 90) {
return "Grade: A";
} else if (score >= 80 && score < 90) {
return "Grade: B";
} else if (score >= 70 && score < 80) {
return "Grade: C";
} else {
return "Grade: F";
}
}
// Testing all letters
console.log(getGrade(95)); // Grade A
console.log(getGrade(85)); // Grade B
console.log(getGrade(75)); // Grade C
console.log(getGrade(65)); // Grade F
<IPython.core.display.Javascript object>
%%js
//HACK 3
function convertTemperature(value, scale) {
//check farenheight or celcius and convert the temp
if (scale === "C") {
// Convert Celsius --> Fahrenheit
const fahrenheit = (value * 9/5) + 32;
return fahrenheit + "°F";
} else if (scale === "F") {
// Convert Fahrenheit --> Celsius
const celsius = (value - 32) * 5/9;
return celsius.toFixed(2) + "°C"; // Rounding to two decimal places
} else {
return "Error: Invalid scale. Use 'C' for Celsius or 'F' for Fahrenheit.";
}
}
console.log(convertTemperature(0, "C")); // 32 degrees farenheight
console.log(convertTemperature(32, "F")); // 0 degrees celcius
<IPython.core.display.Javascript object>
BIG HACKS 3.7.3
HACK 1 (conditions to go to the beach)
The weather must be warm.
You must wear a swimsuit.
You must bring enough food.
If all conditions are met, print you are ready to go the beach.
If the weather is not warm, print it is a bad day to go to the beach.
If you don't have a swimsuit, print you need to buy a swimsuit.
If you don't bring enough food, print you need to buy/bring more food.
Hack 2 (Conditions to adopt a pet)
You must be 18 years or have a gaurdian.
you must have the finances to afford animal supplies and care for the animal.
You must have the time to care for an animal.
If all conditions are met, print you can adopt a pet.
If you are not old enough or have a gaurdian, print you must be 18 or older to adopt a pet.
If you dont have the finances to care for a pet, print you need more money to care for a pet.
If you do not have the time, print you need more time to care for an animal.
Hack 3 (conditions to partisipate in a marathon)
The weather must be clear.
You must have running shoes.
You must have practiced for at least 10 days.
If all conditions are met, print you are ready to do a marathon.
If you don’t have running shoes, print you need to buy shoes first.
If you haven’t practiced enough, print you need to practice more first.
If the weather is not clear, print it is not the right weather to do a marathon.
Python Quiz Awsners
Question 1: C. “you are too young to enter”
Question 2: B. “x is positive but y is not”
Question 3: C. “its too cold”
BIG HACKS 3.7.4
Hack 1 (conditions to study for an exam)
You must have your material (notebooks, textbooks, etc...).
You must have a quiet enviroment to study.
You must be energized enoguh to study.
If all conditions are met, log you are ready to study.
If you do not have study materials, log you must first gather your materials.
If you do not have a quiet enviroment, log you must first find a quiet place to study.
If you do not have energy, log you need to take a nap before studying.
Hack 2 (conditions to bake a cake)
You must have all the ingredients (flour, eggs, sugar, etc...).
you must have a working oven
you must have a minimum of 2 hours of free time
If all conditions are met, log you can bake a cake.
If you do not have all ingredients, log you need to buy ingredients.
If you do not have a working oven, log you must fix or replease your oven.
If you dont have a minimum of 2 hours to bake, log you need more time to bake a cake.
Hack 3 (conditions to go camping)
The weather must be clear.
You must have shelter (a tent or cabin).
You must have enough food and water.
If all conditions are met, log you are ready to go camping.
If the weather is not clear, log it is not the right day to go camping.
If you dont have shelter, log purchase a tent or cabin before going camping
If you dont have enough food and water, log you need to pack more food and water before going camping.
Javascript Quiz Awsners
Question 1: B. “Grade: B”
Question 2: B. “Member discount applies”
Question 3: A. “lets go to the park!”