Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings.

Similar presentations


Presentation on theme: "CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings."— Presentation transcript:

1 CSC 1701B Computing: Science and Creativity

2 Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings will be given)  Lists

3 Types  Character  Single character like A 5 or $  Digit  0 through 9 only  Number  123 -99 0.05  Word  1 or more characters, no space A_word Cat !@#$  Sentence  One or more words with spaces

4 Variables and Scripts  Names that can store values that change  May be global (known everywhere) like this:  Or a script variable known only in that script

5 Operators  Some operators only allow digits or numbers + - x / mod round  Some operators allow many types  BTW, case does not matter  Others allow a mix of types

6 Control  Sequential  one block call after another  Selection  if if…else  Repetition  repeat until for  Selection and repetition can be nested  You won’t need to write nested control on the Midterm

7 Functions  Functions take in 0 or more inputs and return exactly 1 output  The same inputs MUST yield same outputs  Output function of input only  Other rules of functions  No state (prior history)  No mutation (no variables get modified)  No side effects (nothing else happens) CS Illustrated function metaphor

8  Domain  The type “class” of input a function accepts  Examples  Sqrt of  Positive numbers  Length of  Sentence, word, number  _ < _  Both: Sentence, word, number  _ and _  Booleans  Letter _ of _  Number from 1 to input length  Sentence, word, number  Range  All the possible return values of a function  Examples  Sqrt of  Non-negative numbers or Nan  Length of  Non-negative integer  _ < _  Boolean (true or false)  _ and _  Boolean (true or false)  Letter _ of _  Letter More Terminology (from Math)

9 Why use functions? (1) The power of generalization!

10 Why use functions? (2)  Functions can be composed together to make even more magnificent things  Functions are the building blocks of almost everything we create when programming  Functional decomposition: the process of breaking big problems down into smaller tasks

11  Command  No outputs  Meant for side-effects  Not a function…  Not on Midterm  Reporter (Function)  Any type of output  Predicate (Function)  Only Boolean output  (true or false)  You will not need to write any block headings on the MidTerm Types of Blocks

12  You will be asked to complete blocks on the midterm, given the block heading  Example: Complete this custom block to return the smaller of two values: write the text, use ( and ) if (a < b) set smaller to a else set smaller to b report smaller Writing Snap! On Paper

13  would be written as ((a > b) and (a < 999))  Practice test question shows how to write Snap! Writing Snap! On Paper

14 We often need to store a collection of items Snap! has the list block Found under Variables The following list has 3 elements It is considered an anonymous list as it has no nameno name Lists 14

15  By default, a list has 1 item that is an empty word  To create an empty list, click the left arrow to remove it New lists can have one nothing ITEM 15

16 A named list with 3 elements 16  Give a name to an “empty” list, add 3 names  Show all, first, last, and any element in the list known as names names is a list with zero elements

17 Other blocks you may need 17  These will be added to the question ifthey will be needed (no need to memorize Snap blocks)  length is # items in the list  add adds at the end  insert places a new thing at the given index 1..length  delete removes the thing at the given index

18  No need to memorize blocks  You will see needed blocks in other questions on the Midterm  Or they will be given for that problem  Give a preview of the practice test And finally


Download ppt "CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings."

Similar presentations


Ads by Google