Lab #7 Write Up

Name: Kelly Yokoi

Period: 7

Assignment: Lab #7

Lab Overview

Scratch Lab #7 focused on blocks in scratch. For problem #1 I had to make a block that calculated the distance formula. For Problem #2 I had to make a sprite convert feet into miles or inches.

My Solution Problem #1

I created 4 variables named x1, y1, x2, y2 just like the variables in the distance formula. I had the sprite ask the user what the variables are as they represent the coordinates they would like to find the distance between. I had each variable equal the user's answers.Then I had the sprite calculate and say the distance by putting a square root operator with the part of the distance formula that's inside the square root ((x2-x1)(x2-x1)+(y2-y1)(y2-y1))in a speech bubble block. This is what I defined as Distance formula.

Problem #1

My Solution Problem #2

For Problem #2 I defined a block called "feet." The block would make the sprite as the user "how many feet?" and I used an if...then...else block. In the "if" section I have 3 operator blocks. If the answer equaled 5280 or is greater than 5280 then the answer will be divided by 5280 and give the answer in miles. For anything else the answer will be mutliplied by 12 and give the answer in inches.

Problem #2

Questions

  1. Question #1-Blocks

    What are two advantages to using blocks for code repetition?

    • Using blocks for code repetition is very helpful as it makes it so the programmer doesn't have to keep putting the same exact code over and over again in different places. Defining it saves space and time.
  2. Question #2-Parameters 1

    What are parameters?

    • Parameter is a kind of variable to refer to a piece of data called arguments.
  3. Question #3-Parameters 2

  4. Give an example of a formula that takes at least one parameter.

  5. Question #4-Parameters 3

  6. Give an example of a situation where no parameters are needed.

  7. Question #5-Block

  8. Explain what you think the following program does. How do blocks make this easier to understand? Explain what you would expect within each block.

Click HERE to return to homepage.