3.3
Popcorn Hack #1
def output(x):
print(8 * (x - 2) + 9)
number = float(input('Enter an x value'))
output(number)
Popcorn Hack #2
number1 = 11
number2 = 2
number3 = number1 % number2
number4 = number3 * number1 + 70
#answer will be 81
print(number4)
Popcorn Hack #3
numberl = [14, 18, 19, 23]
for num in numberl:
remainder = num % 3
if remainder == 0:
print(num, "is divisible by 3")
else:
print("The remainder when", num, "is divided by 3 is", remainder)
Homework Hack
#fibonacci
def fibonacci(n):
if n <= 0:
return "Input should be a positive integer"
elif n == 1:
return 0
elif n == 2:
return 1
else:
a, b = 0, 1
for _ in range(n - 2):
a, b = b, a + b
return b
number = int(input('enter an integer:'))
print(fibonacci(number))
#calculating area of shapes
import math
def calculate_area():
shape = input("Which shape do you want to calculate the area for? (circle, square, rectangle): ").lower()
if shape == "circle":
radius = float(input("Enter the radius of the circle: "))
return f"The area of the circle is: {math.pi * (radius ** 2)}"
elif shape == "square":
side = float(input("Enter the side length of the square: "))
return f"The area of the square is: {side ** 2}"
elif shape == "rectangle":
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
return f"The area of the rectangle is: {length * width}"
else:
return "Invalid shape for area calculation."
print(calculate_area())
#calculating volume
def calculate_volume():
shape = input("Which shape do you want to calculate the volume for? (rectangular prism, sphere, pyramid): ").lower()
if shape == "rectangular prism":
base = float(input("Enter the base length of the rectangular prism: "))
width = float(input("Enter the width of the rectangular prism: "))
height = float(input("Enter the height of the rectangular prism: "))
return f"The volume of the rectangular prism is: {base * width * height}"
elif shape == "sphere":
radius = float(input("Enter the radius of the sphere: "))
return f"The volume of the sphere is: {(4/3) * math.pi * (radius ** 3)}"
elif shape == "pyramid":
base = float(input("Enter the base length of the pyramid: "))
width = float(input("Enter the width of the pyramid: "))
height = float(input("Enter the height of the pyramid: "))
return f"The volume of the pyramid is: {(1/3) * base * width * height}"
else:
return "Invalid shape for volume calculation."
print(calculate_volume())
3.5
Popcorn Hack #1
var first_variable = true;
var second_variable = false;
if (first_variable == true) {
console.log("The first variable is true");
} else if (first_variable == false) {
console.log("The first variable is false")
}
if (first_variable == true && second_variable == false) {
"The first variable is true and the second one is false"
}
if (first_variable == true || second_variable == true) {
"Either the first or the second variable is true"
}
first_variable = True
second_variable = False
if first_variable:
print("The first variable is true!")
else:
print("The first variable is false!")
if first_variable and not second_variable:
print("The first variable is true and the second one is false")
if first_variable or second_variable:
print("Either the first or the second variable is true")
Popcorn Hack #2
number = float(input('Enter a number'))
if number > 10:
print("number is greater than ten!")
else:
print("number is not greater than ten!")
Popcorn Hack #3
number = float(input('Enter a number'))
if number >= 100 and number <= 999:
print("The number you entered is 3 digits")
else:
print("The number you entered is not three digits!")
Homework Hack
def de_morgan_law():
print("A B Result")
values = [False, True]
for A in values:
for B in values:
result = (not (A and B)) == ((not A) or (not B))
print(f"{A} {B} {result}")
de_morgan_law()
A B Result
False False True
False True True
True False True
True True True