Introduction to Computer Programming

Scratch Lab #9

Lists

Table of Contents


Pair Programming:

Summing a List

Individual Lab:

Problem #1-Even or Odd

Problem #2-Distance and Regular Polygons

Question #1

Question #2

Question #3

Question #4

Question #5

Pair Programming:

Summing a List

Write a program in Scratch that will use a list.  The list will store a group of random numbers and then sum up that list of random numbers.

Step One:  Go to the data section and make a list named numbers.  Numbers will be used by all sprites and will be used to store a list of random numbers.

Step Two:  


Individual Lab:

You must complete 1 of the following 2 problems.  If you adequately complete those problems and still have time, you are expected to continue working on the other problems.  You are assessed on both the correctness of your code as well as full use of the lab time given during class.

You need to be able to answer all of the following questions.  Your answers will be posted on your website.

Problem #1-Even or Odd

You will write a simple calculator that can determine if a number is even or odd.  

  1. You will need to use some modular arithmetic (looking at the remainder of a division problem).  What is special about even numbers and odd numbers when they are divided by two.
  2. Your program should have the following output:
  3. User enters 3 (or any odd number)

  1. User enter 4 (or any even number)

Once you have your calculator working, create your own block called “calculate Even or Odd”.

Screen Shot 2015-08-01 at 6.56.04 AM.png

Problem #2-Distance and Regular Polygons

Use the more blocks function within scratch to create a block that calculates the distance between two points.  Note, you should access values from a list.  One option is to have a list of x-values and another list that stores the y-values.  You should call this function on a sprite as follows:  

        To test your calculator, the following outputs should occur:

Using your code block from the above question, create a program that allows a user to determine if a polygon is a regular polygon (all sides equal length) by entering the coordinates of the polygon.  The pseudocode for this is something like:

Question #1

What is the length of an “empty” list?

Question #2

Why are lists more powerful than variables?

Question #3

Can a list contain different data types?  For example, could it store both numbers and words?