Introduction to Computer Programming
Scratch Lab #3
Variables & Conditionals
Table of Contents
Pair Programming-Conditionals:
Problem #1-Quick Costume Change
Problem #4-Rock, Paper, Scissors
Question #1-Variable Definition
Question #6-Control Structures
Question #8-Compound Conditionals
Question #9-Compound Conditionals 2
Question #10-Nested Conditionals
Write a program in which two sprites are bouncing around the stage. You can start their directions randomly. If the two sprites touch, they should say “ouch” and then continue and speed up their motion. If the two sprites happen to touch in the 3rd quadrant, where both x and y values are negative, the sprites should glide to the first quadrant and continue their motion. You can use a variable for speed and embed this in the “move __ steps” block. Speed should be set to 5 to start the program. If the speed of the sprites is greater than 50 steps, the program should end.
You must complete 3 of the following 5 problems. If you adequately complete those three 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.
Create a simple animation using the built in costumes for any sprite you choose. You should use a forever loop so that the animation won’t end. Add another sprite to act as a button. Name this sprite “Faster”. Add another sprite that also acts as a button. Name this sprite “Slower”. Using a variable called “speed”, have the faster button speed up the animation and the slower button slow it down.
Build a program where a sprite asks for the following information (the answers should all be stored as variables)
The sprite should then have a ‘conversation’ with another sprite (who wasn’t on the screen until now) about the cool person they just met.
Write a program that takes two ordered pairs of points and calculates the distance between them. Hint: You might want to use 4 variables. Test your program with a known distance. For example, the ordered pairs (2, 3) and (5, 7) should have a distance of 5 units.
Create a dance party where at least three sprites are dancing. There should be music in the background. Add a sprite that controls the volume of the music. If the music gets too loud, determined by you, the police should come and everyone run off the screen. Note, you will need a conditional (if statement) in a forever loop to determine if the volume is too high
Create a program that takes a measurement in feet and inches and converts it to metric units of mm, m and km. You should have at least 5 variables (you might want 6). The sprite should ask the user for both feet and inches and store these values as separate variables. Then after performing some calculations, the values for mm, m and km should be ‘set to’ to appropriate values. You should check your numbers to make sure your output is correct. If you are unsure on your conversions use the following link:
https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=convert+feet+to+meters
You must complete 2 of the following 4 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.
Write a program in Scratch that will make a sprite move up, down, left, and right. The sprite will draw lines on the screen as it moves.
Make the sprite move and draw lines as it moves.
Write a program in scratch in which a sprite, you can choose, changes costumes continually. Create a button, called ‘faster’, that increases the speed at which the sprite changes costume. There should be a variable called speed that is directly controlled by the faster button. Further, create another sprite called ‘slower’ that slows down the speed of the costume changes. Lastly, create another variable called ‘maxSpeed’ which stores the fastest speed reached (careful with your conditional here!).
Create a sprite which takes a word as input and then spells the word back to the user one letter at a time. If the word is longer than 10 letters then the sprite should ask for a new word.
Create a program that will allow a user to play rock paper scissors against the computer. The computer can randomly select it’s choice. Have a variable that tracks the number of wins. If you would like an extension, create a version of Rock, Paper, Scissors, Lizard, Spock
Are variables in computer programming the same as variables in math class? Why or why not?
When creating a variable, what are the two types of scope a variable can have? That is, what can it affect. (Think about your options as you make a variable)
How many values can a variable store at one time?
What will the following code snippet do? Explain why it doesn’t work as intended.
Given the following code snippet, explain what is happening.
What is the difference between and if and and if-else statement?