Understanding Functions in Programming with Examples

Slide Note
Embed
Share

Explore the concept of defining functions in programming with examples using solid green triangles, blue circles, and solid color circles. Learn to write contracts, provide examples, and define functions step by step. Discover how functions work in algebra and create your own function that adds 1 to a variable.


Uploaded on Sep 29, 2024 | 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. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. DAY 6 OF BOOTSTRAP DEFINING FUNCTIONS S I T I N YO U R PA I R S . G R A B YO U R C H R O M E B O O K S A N D L O G I N TO W E S C H E M E . O R G

  2. I LOVE GREEN TRIANGLES Wescheme

  3. Defining Functions gt will be a function that makes a solid green triangle ( gt 10) would be a shortcut for ( triangle 10 solid green ) gt is the function, 10 in the input-domain

  4. Steps to define a function 1.Write a contract 2.Give Examples 3.Define Function ????:?????? ????? Turn to page 9: Fast Functions Lets work through writing a contract together

  5. Defining Functions Write a function gt , which takes in a number and gives back a solid, green triangle of the given size. gt Number size Image gt gt 10 11 10 (triangle solid green ) (triangle solid green ) 11 gt size ((triangle solid green ) size 5

  6. Defining Functions Confession: I lied. I actually prefer blue circles! Write a function bc , which takes in a number and gives back a solid, blue circle of the given radius. Image bc Number radius bc bc 16 99 16 (circle solid blue ) (circle solid blue ) 99 bc radius ((circle solid blue ) radius 6

  7. Define a function: dot which takes in a color (domain) and produces(range) a solid circle of the given color with a radius of 20 (define (dot color) (circle 20 solid color))

  8. How does this work in Algebra? define f x + x 1 1. Name of function? 2. How many variables? 3. What is the name of the variable(s)?

  9. Define a function f that takes in a variable x and adds 1 ?????? ? ? + ? 1 In algebra in written as ? ? = ? + 1

  10. Define a function g that takes in a variable r and multiples it by 20 ?????? g r r 20 In algebra in written as ? ? = ?(20)

  11. Define a function h that takes in a variable x and divides it by 2 ?????? ? / ? 2 ? =? In algebra in written as 2

  12. Page 38: Complete function definitions

  13. Rocket Height page 12

  14. Rocket-height rocket-height rocket-height Number Number Multiply the number of seconds by 7 to find the height radius seconds 105 15 (* 7 15) (* 7 289) rocket-height 289 15

  15. Google: Wescheme Rocket-Height Follow 1st link Can you fix the game? Wescheme

Related