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.3 Recap
2
Creating an Account
3
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
Intro to EduBlocks
5
Python 3 project
Intro to EduBlocks
6
Intro to EduBlocks
7
Intro to EduBlocks
8
Intro to EduBlocks
9
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
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
Variables & Printing
1
12
Creating Variables
Variables are used in EduBlocks to store all kinds of data – from numbers to words!
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)
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
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
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
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
Creating and Printing Variables
Now you try!
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)
Conditional Statements
2
19
Conditional Statements
Conditional statements check if something is true. (We’ll use “if” statements a lot!)
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!
Conditional Statements
If statements are constructed by dragging a comparison:��
into a green if block:
21
Conditional Statements
Both these blocks (and lots of others!) are found under the “Logic” tab. �
Here are the comparisons we can make:
22
Conditional Statements
Now you try!
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!
Loops and Iteration
3
24
Variable Lists
Lists in EduBlocks store more than one value at a time!
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!
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” |
Variable Lists
For loops can be used to iterate through each item in a list by index.
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!
Variable Lists
For loops can be combined with if statements to check a list for a value!
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!
Build Your Own!
Create a new program in EduBlocks. This program should:
29
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?
30
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