Hack 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?
  • It is important to know that algorithms looks different is because there will be a difference can make it wrong, even they looks the same.
  • for the converted conditional to boolean conversion
isSolid = False
isSoft = True

if isSolid == True:
    print("Don't Eat it")
else:
    if isLiquid == True:
        print("Eat it")
    else:
        print("Don't eat it")
Eat it
isSolid = False
isSoft = True

eatTime = not(isSolid) and isSoft
if eatTime == False:
    print("Don't eat it")
if eatTime == True:
    print("Eat it")
Eat it

Hack 2

Develop your own complex algorithm using a flowchart and natural language, then code it!

Requirements:

Includes both a flowchart AND natural language Working code of the same algorithm Incorporates selection AND/OR iteration Make it creative!

  1. Input what show user is looking for
  2. check if show is in show dictionary
  3. If it is in dictionary, move onto step 4. If not, print "not available"
  4. check if the show has a rating of 3 or higher
  5. If it does, print "recommended"; if it doesn't print "not recommended"
itemdictionary = {
    'item1':2,  
    'item3':3, 
    'item4':5,
    'item5':1
}
show = input("What item are you looking for?")
if show in showdictionary.keys():
    print(show + " is available")
    if showdictionary[show] >= 2:
         print("recommended")
    else:
        print("not recommended")
else:
    print(show + " is not available")
7 is not available

Hack 3

  1. Make a flow chart for the algorithm number guessing game.
  2. Make a function that gets the user guess.
  3. Modify the existing search function to give more encouraging feedback.
import random

num_guesses = 0
user_input = -1
upper_bound = 10
lower_bound = 0

number = random.randint(0,10)

print("Think a number between 0 and 100.")

def guess():
    num = input("Choose a number!")
    return num 

def search(number, guess):
    global lower_bound, upper_bound
    if int(guess) < int(number):
        print("You guessed too low") 
        lower_bound = guess
        return lower_bound, upper_bound
    elif int(guess) > int(number):
        print("You guessed too high")
        upper_bound = guess
        return lower_bound, upper_bound
    else:
        upper_bound, lower_bound = guess, guess
        return lower_bound, upper_bound 

while user_input != number:
    user_input = guess()
    num_guesses += 1
    print(f"You guessed {user_input}.")
    lower_bound, upper_bound = search(number, user_input)
    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!")
Think a number between 0 and 100.
You guessed 8.
You guessed too high
Guess a number between 0 and 8.
You guessed 5.
You guessed too low
Guess a number between 5 and 8.
You guessed 6.
You guessed too low
Guess a number between 6 and 8.
You guessed 7.
You guessed the number in 4 guesses!

Hack 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
  2. Using one of the sets of numbers from the question above, what would be the second number looked at in a binary search if the number is more than the middle number?
  • It's 80, 74, and 96
  1. Which of the following lists can NOT a binary search be used in order to find a targeted value?

    a. ["amy", "beverly", "christian", "devin"]

    b. [-1, 2, 6, 9, 19]

    c. [3, 2, 8, 12, 99]

    d. ["xylophone", "snowman", "snake", "doorbell", "author"]

    C

index = [12, 14, 43, 57, 79, 80, 99]
index.sort()
mid = int(len(index) / 2) 
print("middle is",index[mid])
middle is 57
index =[1, 12, 30, 43, 66, 74, 92]
index.sort()
mid = int(len(index) / 2) 
print("middle is",index[mid])
middle is 43
index = [7, 13, 33, 60, 84, 96, 111]
index.sort()
mid = int(len(index) / 2) 
print("middle is",index[mid])
middle is 60