Page 205 - Learn To Program With Scratch
P. 205
Problems
1. Create an input validation loop that only accepts numbers in the range
of 1 through 10.
2. Write a script that asks the user, “Are you sure you want to quit [Y, N]?”
The script then checks the user’s input and only accepts the letters Y
and N as valid answers.
3. Write a program that calculates and displays the sum of all integers
between 1 and 20.
4. Write a program that calculates and displays the sum of all odd integers
between 1 and 20.
5. Write a program that displays
the first 10 numbers in the
following sequence (using
the say command): 5, 9, 13,
17, 21, ....
6. What does the script on the
right do? Implement the
script and run it to check
your answer.
7. If the remainder of dividing a whole number (x) by another whole
number (y) is 0, we say that y is a factor of x. For example, 1, 2, 4, and
8 are factors of 8. The script below finds and displays all the factors of
a given number (other than the number itself). Study this script and
explain how it works. What are the outputs of this script when the input
numbers are 125, 324, and 419?
8. An integer is said to be prime if it is divisible by only 1 and itself. For
example, 2, 3, 5, 7, 11 are prime numbers, but 4, 6, and 8 are not. The
procedure on the next page tests whether a number is a prime number
or not. Study this procedure and explain how it works. What are the
outputs of this procedure for the inputs 127, 327, and 523?
Repetition: A Deeper Exploration of Loops 183
www.it-ebooks.info

