Introduction to Computational Thinking Block Py Python C

  • Slides: 10
Download presentation
Introduction to Computational Thinking Block. Py Python (C) Dennis Kafura 2016 1

Introduction to Computational Thinking Block. Py Python (C) Dennis Kafura 2016 1

Reflections on the Micro project CT@VT n Show your code without explanation to another

Reflections on the Micro project [email protected] n Show your code without explanation to another member of your cohort (while you examine theirs). q q Can you each understand the other’s algorithm? Can you imagine what questions being answered? (C) Dennis Kafura 2016 Slide 2

CT@VT Advantages of Block. Py n n The drag-and-drop interface means that we do

[email protected] Advantages of Block. Py n n The drag-and-drop interface means that we do not need to memorize the syntax of statements. Blockly prevents some kinds of mistakes by allowing only meaningful combination of blocks. The visual layout of an algorithms can help understand its structure Block. Py code (nearly) always does something - even when it is not exactly what we want. (C) Dennis Kafura 2016 Slide 3

CT@VT Advantages of Python n Write statements (lines of code) faster! Use the full

[email protected] Advantages of Python n Write statements (lines of code) faster! Use the full capability of available programming facilities. However, we have to learn its syntax. q q n Keywords: terms or symbols used to indicate the kind of statement being written Punctuation: symbols or indentation used to indicate the end of a statement or its relationship to other statements Fortunately, there is a direct relationship between Block. Py and Python! (C) Dennis Kafura 2016 Slide 4

CT@VT Blocks in Python click the tab (C) Dennis Kafura 2016 Slide 5

[email protected] Blocks in Python click the tab (C) Dennis Kafura 2016 Slide 5

CT@VT What’s new/different here? set temperatures = create list with [65, 72, 87, 66,

[email protected] What’s new/different here? set temperatures = create list with [65, 72, 87, 66, 88] set cool = 0 set warm = 0 for each item temp in list temperatures: if temp < 70: do set cool = cool + 1 elif temp >= 85: do set warm = warm + 1 print(cool) print(warm) (C) Dennis Kafura 2016 Slide 6

CT@VT Indentation 4 spaces 8 spaces (C) Dennis Kafura 2016 Slide 7

[email protected] Indentation 4 spaces 8 spaces (C) Dennis Kafura 2016 Slide 7

CT@VT Indentation n Spaces in front of lines of code. Used to indicate blocks

[email protected] Indentation n Spaces in front of lines of code. Used to indicate blocks that belong inside another block of code. The amount of space matters. ? it w ong r w hat’s ode c s i h th W (C) Dennis Kafura 2016 Slide 8

CT@VT Colons “: ” n n Colons at the end of for and if

[email protected] Colons “: ” n n Colons at the end of for and if blocks indicate the start of indentation. They are mandatory for these two blocks. None of the other lines have colons at the end. temperatures = [65, 72, 87, 66, 88] cool = 0 warm = 0 for temp in temperatures: if temp < 70: cool = cool + 1 elif temp >= 85: warm = warm + 1 print(cool) print(warm) (C) Dennis Kafura 2016 Slide 9

CT@VT For today n n n Work on classwork problems in your cohort This

[email protected] For today n n n Work on classwork problems in your cohort This is our first step into Python so don’t worry if it is awkward or difficult The concepts are the same – only the form is changing! (C) Dennis Kafura 2016 Slide 10