Skip to content

Instantly share code, notes, and snippets.

@ashx3s
Last active September 27, 2023 21:29
Show Gist options
  • Save ashx3s/c81f1e72f83586efcd97206b806fd494 to your computer and use it in GitHub Desktop.
Save ashx3s/c81f1e72f83586efcd97206b806fd494 to your computer and use it in GitHub Desktop.
Afternoon Algorithm Activity

Afternoon Algorithm Activity

Convert a flowchart into the programming language that you're learning.

This activity does not involve rendering any graphics or dealing with complex data as it is intended for improving your ability to build small clear algorithms. In some cases, you might be mostly writing in comments and that's ok. The objective is to connect the nouns, verbs, repetition, and decisions to variables, functions, loops, and conditionals and visualize how to return desired results.

Instructions

Remember that we are still mostly flow charting and that fully functional code is not the focus

  1. Pick one of the steps that you had outlined in a flow chart
  2. Create variables for anything noted as a noun:
    • this can be just a string, but might require objects if there are relevant attributes of the variable
    • pay attention to variables that are subject to change or be constant
  3. Create a conditional statement for any decisions that need to be made:
    • In code terms (ie: height > 10), what is the condition that needs to be satisfied
    • What are the other options?
    • What is the result of the condition being met?
    • What is the result of the condition being not met?
  4. Create loops for any repeated actions (pick a loop based on the following criteria)
    • what is being repeated
    • when does the repetition start
    • what is the condition of which the loop stops
    • what type of loop makes the most sense to use?
  5. Create functions for all the actions and outline the following:
    • input values (if needed)
    • return value (what is the result of the action)
    • steps of the action (small steps inside of the function - mostly do this with comments)
    • error handling (are there any notable conditions that would make this not work right?)

Outcome

You should have a file written in your programming language of choice with a mix of pseudocode and actual code. Use this activity to familiarize with how your language is used to solve problems.

Refer to docs when picking types of syntax to use. This exercise will help you become comfortable with the rules of your language while also making it easier to visualize how to program different situations.

Link to initial activity that this activity builds upon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment