what are the three components of an algorithm?

  • selection
  • sequence
  • iteration

Whats the main idea?

  • Different algorithms can be used to solve the same problem

Why is it important?

  • When 2 algorithms look extremely similar, it is easy to assume they do the same thing. However, that is not the case and we have learn how to notice small differences in code and pretty much debug.
  • just know that codes that look similar don't always produce the same things

Hacks

  • 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)
  • for the converted conditional to boolean conversion(0.10)
  • total: 0.25

It is important to know the difference between algorithms because it allows you to predict the outcome to a certain situation that the algorithm involves.

tired = False
time = True


work = not(tired) and time
if work == False:
    print("stay at home!")
if work == True:
    print("go to work!")
go to work!

Hacks

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!

Tips:

  • This site is good for making flowcharts!
  • Natural language should just be a list
  • Think about the whole process, not just the end result

ImageOne

  1. are you awake? if not run again.
  2. are you sick?
  3. No, go to work. Yes, Don't go to work.
awake = True
sick = False

if awake and not sick:
    print("Go to work")
    
else: 
    print("stay at home")
    
Go to work
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():
    #get a guess from the user
    user_guess = int(input("Enter your guess: "))
    return user_guess

#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 guess < number:
        print("Your guess is too low.") #change this
        lower_bound = guess
    elif guess > number:
        print("Your guess is too high.") #change this
        upper_bound = 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)
    print(f"Guess a number between {lower_bound} and {upper_bound}.")

print(f"You guessed the number in {num_guesses} guesses!")
I'm thinking of a number between 1 and 100.
You guessed 50.
Your guess is too high.
Guess a number between 0 and 50.
You guessed 25.
Your guess is too low.
Guess a number between 25 and 50.
You guessed 33.
Your guess is too high.
Guess a number between 25 and 33.
You guessed 28.
Your guess is too low.
Guess a number between 28 and 33.
You guessed 30.
Guess a number between 28 and 33.
You guessed the number in 5 guesses!

ImageTwo

  • 12, 14, 43, 57, 79, 80, 99
  • 57
  • 92, 43, 74, 66, 30, 12, 1
  • 43
  • 7, 13, 96, 111, 33, 84, 60
  • 60

ImageThree

ImageFour

ImageFive

  • It will take the number in between