Computing, Science, and Creativity Lecture Review: SNAP! Overview

csc 1701b n.w
1 / 18
Embed
Share

Discover the key concepts covered in Lecture #17 of CSC.1701B, focusing on types, variables, operators, control structures, functions, and more. Explore the importance of functions in programming and delve into terminology from mathematics related to computing. Get insights into using functions for generalization and abstraction.

  • Computing
  • Science
  • Creativity
  • Programming
  • Functions

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CSC 1701B Computing: Science and Creativity LECTURE #17 SNAP! REVIEW

  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. More Terminology (from Math) 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

  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. Types of Blocks 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

  12. Writing Snap! On Paper 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

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

  14. Lists 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 name 14

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

  16. A named list with 3 elements 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 16

  17. Other blocks you may need 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 17

  18. And finally 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

Related


More Related Content