1 of 31

API CAN CODE �Computational Foundations of �Data Science

Lesson 2.R: Introduction to EduBlocks

This work was made possible through generous support from the National Science Foundation (Award # 2141655).

2 of 31

2.3 Recap

  • Last lesson we learned about the JSON format of data, which stores values paired with a key, and used it to view some data from a small Mario Kart dataset�
  • Did some debugging on a program working with the Mario Kart dataset in the last exit ticket!

2

3 of 31

Creating an Account

3

4 of 31

Intro to EduBlocks

EduBlocks is a block-based programming tool that helps novices learn how to code with text-based programming languages.

4

Block-view

Code-view

5 of 31

Intro to EduBlocks

Go to: app.edublocks.org/editor

Create an Account

Create a new “Python 3” project

5

Python 3 project

6 of 31

Intro to EduBlocks

  • Now that you have an account, you can clone projects from others, which will let you create your own version of the project that you can modify and save to your account.

6

7 of 31

Intro to EduBlocks

  • Once you have cloned a project, you can save it to permanently add it to your account’s projects so you don’t lose it.

7

8 of 31

Intro to EduBlocks

  • By clicking on the name of your saved project, you can also rename it. �
  • This will make it easier to keep track of which projects are which!

8

9 of 31

Intro to EduBlocks

  • You can also share any of your own projects. �
  • After clicking the “Share” button in the top-right, switch the project to “public” and copy the link to share it with anyone.

9

10 of 31

Intro to EduBlocks

On the left we have all of the blocks we can use to write code.

The blocks are organised in the left menu by their function.

10

11 of 31

Intro to EduBlocks

To run our code, click the blue run button. This will show the output on the right of the screen (Python 3).

11

Run/Stop button

12 of 31

Variables & Printing

1

12

13 of 31

Creating Variables

Variables are used in EduBlocks to store all kinds of data – from numbers to words!

  1. Open this example program, then clone it, save it to your library, and rename it so you remember what it does! Then, run it!

13

beginning of the program!

gives “x” a value: the number 17

prints JUST the number stored in “x” (17)

prints some text, then the value of “x” (17)

14 of 31

Creating Variables

To create a new variable, we go into the “Variables” tab and click “Create Variable…” which will bring up a pop-up to name your new variable.

To store a value in this variable, drag the block into your code space, use the drop-down button to select the variable you want, and type the value in place of

14

15 of 31

Printing Variables

To print variables, we go to the “Statements” tab.

The top block is best for pre-set statements.

The bottom block is useful for printing variables and combinations.

15

16 of 31

Printing Variables

Sometimes, we just want to print a variable by itself and nothing else. In this case, we can use the orange print statement and drag the variable we want from the Variables tab directly into the blank.

16

17 of 31

Printing Variables

Other times, we might want to print an explanation with the variable, or something else along with it.�

In this case, we can just type “Word stuff”, x. �The quotes (“ “) tell EduBlocks that there are words inside, and �the comma (,) tells it to join the pieces together to print out.

17

18 of 31

Creating and Printing Variables

Now you try!

  1. In your version of this example program, create a new variable y, store the number 85 in it, and create two print statements similar to the ones for x.

18

beginning of the program!

gives “x” a value: the number 17

prints JUST the number stored in “x” (17)

prints some text, then the value of “x” (17)

19 of 31

Conditional Statements

2

19

20 of 31

Conditional Statements

Conditional statements check if something is true. (We’ll use “if” statements a lot!)

  1. Open this example program, then clone it, save it to your library, and rename it so you remember what it does! Then, run it!

20

stores numbers in variables �a, b, and c

checks if a is at least 100. if it is, then we go inside…

…to the orange print statement, which only runs if a >= 100.

this group does the same, but for b!

21 of 31

Conditional Statements

If statements are constructed by dragging a comparison:��

into a green if block:

21

22 of 31

Conditional Statements

Both these blocks (and lots of others!) are found under the “Logic” tab. �

Here are the comparisons we can make:

  • == (checks if equal)
  • > (checks if greater)
  • < (checks if less than)
  • >= (checks if greater or equal to)
  • <= (checks if less than or equal to)

22

23 of 31

Conditional Statements

Now you try!

  1. Using this example program, add a third if statement that checks if c >= 100, and if it is, prints �“c has 3 digits”�
  2. Use the drop-down menu of �to choose >=!

23

stores numbers in variables �a, b, and c

checks if a is at least 100. if it is, then we go inside…

…to the orange print statement, which only runs if a >= 100.

this group does the same, but for b!

24 of 31

Loops and Iteration

3

24

25 of 31

Variable Lists

Lists in EduBlocks store more than one value at a time!

  1. Open this example program, then clone it, save it to your library, and rename it so you remember what it does! Then, run it!

25

my_list stores 3 text values, each a name

the purple for block goes through each value in the list

this print block gets used 3 times because it’s in a loop!

26 of 31

Variable Lists

Values stored in a list are stored in order by index, referenced by [#].

Test: try this print statement: �

What prints out? Was it what you expected? What do you think this would do?

26

index value

reference

value stored

0

my_list[0]

“Jeff”

1

my_list[1]

“Georgia”

2

my_list[2]

“Frank”

27 of 31

Variable Lists

For loops can be used to iterate through each item in a list by index.

  1. In our example program, the counter variable i is used to iterate through the full list by index. �
  2. Note what happens: first my_list[0] is printed, then my_list[1], then finally my_list[2] (the end of the list)

27

my_list stores 3 text values, each a name

the purple for block goes through each value in the list

this print block gets used 3 times because it’s in a loop!

28 of 31

Variable Lists

For loops can be combined with if statements to check a list for a value!

  1. Modify our example program, adding a green if statement so that the element of my_list only prints out if it is “Georgia”. (in other words, the program should only print “Georgia”).

28

my_list stores 3 text values, each a name

the purple for block goes through each value in the list

this print block gets used 3 times because it’s in a loop!

29 of 31

Build Your Own!

Create a new program in EduBlocks. This program should:

  • Create a list with three items:
    • 85
    • 17
    • “Apple”
  • Use a for loop to iterate through all items in this list, and
  • Use an if statement to check whether the position in the list stores “Apple”
    • If it does store “Apple,” print “Found it!”
    • If it does not store “Apple”, print “Hmm… this is [value].” Example: “Hmm.. this is 85.”

29

30 of 31

EduBlocks - Exit Ticket

You are given the following code to evaluate a list for missing values. What indices in the list will it return as missing?

    • 0 and 6
    • 1 and 7
    • 1, 2, 3, 4, and 5
    • 2, 5, 6, 7, and 10

30

31 of 31

Thanks!

apicancode@umd.edu

31

This work was made possible through generous support from the National Science Foundation (Award # 2141655).

API Can Code is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

4.0 International (CC BY-NC-SA 4.0) License