Skip to the content.

3.3 Hacks

Tri 1 Team Teach Hacks

Popcorn Hack 1

x = int(input("Pick an integer for x!"))
print(2*x+5)

Popcorn Hack 2

Code will print: 86

number1 = 8
number2 = 3
number3 = number1 % number2
number4 = number3 * number1 + 70
print(number4)
86

Popcorn Hack 3

numbers = [14, 20, 100, 99, 9, 15]
for num in numbers:
    if num % 3 == 0:
        print(num, "is divisible by 3!")
    else:
        print(num, "isn't divisible by 3!")
14 isn't divisible by 3!
20 isn't divisible by 3!
100 isn't divisible by 3!
99 is divisible by 3!
9 is divisible by 3!
15 is divisible by 3!

Homework Hack

import math
def fibonacci_sequence(n):
    if n <= 0:
        return []
    elif n == 1:
        return [0]
    elif n == 2:
        return [0, 1]
    else:
        fib_sequence = fibonacci_sequence(n - 1)
        fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
        return fib_sequence
n = int(input("Enter an integer: "))
print("The first",n,"terms of the fibonacci sequence is:", fibonacci_sequence(n))
r = int(input("Enter a radius for the circle: "))
s = int(input("Enter a length for the side of the square: "))
l = int(input("Enter a length for the rectangle: "))
w = int(input("Enter a width for the rectangle: "))
b = int(input("Enter a base length for the rectangular prism: "))
l2 = int(input("Enter a length for the rectangular prism: "))
h = int(input("Enter a height for the rectangular prism: "))
r2 = int(input("Enter a radius for the sphere: "))
b2 = int(input("Enter a base length for the pyramid: "))
w2 = int(input("Enter a width for the pyramid: "))
h2 = int(input("Enter a height for the pyramid: "))
area_of_circle = (r**2)*math.pi
print("The area of the circle is:", area_of_circle)
area_of_square = s**2
print("The area of the square is:", area_of_square)
area_of_rectangle = l*w
print("The area of the rectangle is:", area_of_rectangle)
volume_of_rectangular_prism = b*l2*h
print("The volume of the rectangular prism is: ", volume_of_rectangular_prism)
volume_of_sphere = (4/3)*math.pi*(r**3)
print("The volume of the sphere is: ", volume_of_sphere)
volume_of_pyramid = (1/3)*b2*w2*h2
print("The volume of the pyramid is: ", volume_of_pyramid)