Hacks 1:

why is it important to know that algorithms that look different can do the same thing and that algorithms that look the same might have different results?(0.15)?

  • it's important to know that algorithms don't need to look similar in order to evaluate a problem. Different looking algorithms can help us understand a topic better. For example, if you have two different algorithms that do the same thing, someone might understand the first one better than the second. Or vice versa
x = 10
y = 5

if x < y:
    print(str(x) + " is less than " + str(y))
else:
    if x > y:
        print(str(x) + " is greater than " + str(y))
10 is greater than 5
x = 10
y = 5

if (x < y) != True :
    print(str(x) + " is greater than " + str(y))
else:
    print(str(x) + " is less than " + str(y))
10 is greater than 5
if car == "ferrari":
    if carColor == "red":
        print("This is your car!!11!!!1!!")
    else: 
        print("This is not your car!!!1!!1!!1!1!!!")
else:
    print("This is not your car!!!!!!111!!!")
if (car, carColor) != ("ferrari", "red"):
    print("This is not your car!!!@!!")
else:
    print("This is your car!!1!@!@!!")

Hacks 2:

  1. check if user wants to access wifi
    1. if no, then break
  2. if true, then check if the user is logged in
    1. if user is not logged in, break
  3. if true, check if user is an admin or not
    1. if user is not logged in, break
  4. if yes, then authorize user to make changes

if access_wifi == True:
    if loggedIn == True:
        if admin == True:
            print("you have accessed your wifi router and are able to make changes")
        else: 
            print("you need to be an admin to make changes")
    else:
        print("you need to log in to access the wifi router")
else: 
    print("don't want to access the router? ok.")

Hacks 3:

import random

#sets variables for the game
num_guesses = 0
user_guess = 0
upper_bound = 100
lower_bound = 0

#generates a random number
number = random.randint(1,100)

# print(number)     #for testing purposes

print(f"I'm thinking of a number between 1 and 100.")

#Write a function that gets a guess from the user using input()
def guess():
    guessNum = input("input your guess please")
    return guessNum

#Change the print statements to give feedback on whether the player guessed too high or too low
def search(number, guess):
    global lower_bound, upper_bound
    if int(guess) < int(number):
        print("Too low") #change this
        lower_bound = guess
        return lower_bound, upper_bound
    elif int(guess) > int(number):
        print("Too high") #change this
        upper_bound = guess
        return lower_bound, upper_bound
    else:
        upper_bound, lower_bound = guess, guess
        return lower_bound, upper_bound 

while user_guess != number:
    user_guess = guess()
    num_guesses += 1
    print(f"You guessed {user_guess}.")
    lower_bound, upper_bound = search(number, user_guess)
    if int(upper_bound) == int(number):
        break
    else:
        print(f"Guess a number between {lower_bound} and {upper_bound}.")

print(f"You guessed the number in {num_guesses} guesses!")

Hacks 4:

  1. calculate the middle index and create a binary tree for each of these lists
    • 12, 14, 43, 57, 79, 80, 99
    • 92, 43, 74, 66, 30, 12, 1
    • 7, 13, 96, 111, 33, 84, 60
  • I know that you can find the median by taking the greatest index number, adding it to the smallest, and then dividing it by 2.
import statistics as st

numlist1 = ["12", "14", "43", "57", "79", "80", "99"]
median1 = st.median(numlist1)
print(median1)

numlist2 = ["92", "43", "74", "66", "30", "12", "1"]
numlist2.sort()
median2 = st.median(numlist2)
print(median2)

# 7, 13, 33, 60, 84, 96, 11
numlist3 = ["7", "13", "96", "111", "33", "84", "60"] 
numlist3.sort(key=int)
median3 = st.median(numlist3)
print(median3)
57
43
60
numlist1:
                   57
                /       \
               14       80
              /  \     /  \
             12  43   79  99

numlist2:
                   43
                /       \
               12       74
              /  \     /  \
             1   30   66  92

numlist3:
                    60
                /       \
               13       96
              /  \     /  \
             7   33   84  111
  1. don't really understand the question

  2. option c. This is because the list given is unsorted.