Scratch Lab #7
Name: Matthew Moorehead
Date: Novemeber 4th, 2015
Assignment: Lab #7
The first problem was to another distance formula but this time we were supposed to use blocks to create it. We had to make 4 parameters which were for the 1st x, 1st y, 2nd x, and 2nd y values. Then we had to use the distance formula to find the answer.
To solve this, I first defined the distance formula block by making a variable distance and making it equal the distance formula and made the values in the formula using the parameters. Then, I made it so that when the flag is clicked, it asks for the answer from the user and then adds the answer to the parameters so it equals that value.
This problem asked us to make a meausrement converter. The user has to say a number in feet and then the lab will make it so that if the value is less than 5280 feet it will convert it into inches and if it is more than 5280 feet it will convert into miles. It is supposed to use a block with one parameter.
To solve this problem, I defined the block by using an if then statement so that if the parameter feet is less than 5280, it multiplies the number by 12 to equal inches. If it is more than 5280, it divides the answer by 5280 to equal miles. Then I made the variable feet equal the answer. Finally I made the variable feet equal the parameter feet.
- What are two advantages to using blocks for code repetition?
- Two advantages of using blocks are that instead of repeating the same code over and over agan, the user can define it once and put it place the definition which makes it a shorter code. The second advantage of blocks is that it is easier fix mistakes if because it is a shorter code.
- What are parameters?
- Parameters are the options under the blocks which includes number input, string input, boolean imput, and label text. They are used to store answers, sort of like variables.
- Give an example of a formula that takes at least one parameter.
- The distance formula equation uses 4 parameters because there are four variables in the equation. So, 4 parameters of x1, y1, x2, and y2 are needed.
- Give an example of a situation where no parameters are needed
- An example is when the user only needs to shorten a long code and doesn't need any values. So if the user wants characters to start dancing, they don't need a parameter because they don't need to store information.
- Explain what you think the following program does? How do blocks make this easier to understand? Explain what you would expect within each block.
- This program makes the names the user inputs into the computer in alphabetical order. It also has a variable "task_complete" so that once it has enough names it puts it in order. Blocks make this easier to understand because the names of the block are shortened words which says what the action does so that it isn't a mystery for what happens in an action. Within each block I would expect that there are definitions of each block which perform the action that the blocks name is. For example, the block "get name" is defined as the answer of the question "What is your name?".