Variables
Todays Lesson
In todays lesson you are going to: Learn to use variables Learn to ask for user input Learn to save the users response for use later Use an if else statement to create a quiz Learn to calculate a users score
Variables
A+B=C
If A=1 and B = 2
What is C?
A, B are variables. They can be changed.
Step 1 Getting a user input:
When the user answers their answer is stored by the computer.
You can use this answer in your program.
Can you get the program to ask the users name and then say Hi, <Name>.
Extension: Create a conversation between the computer and the
user.
Task Create a quiz which asks the user a question.
The computer checks this answer is equal to the correct answer,
if it is CORRECT then it will say it is CORRECT
else it will say it is not right.
Use these building blocks to make your quiz.
Scoring the Game
Go to variables
Make a variable called score.
Set score to 0 at the beginning of the game
If the user gets a question right give them 1 extra score.
Experiment Time!
Time to have a play around with scratch!
Lesson 3
In todays lesson we will:
Revise asking for user input Revise variables
Create a program to carry out maths calculations
Create a program to draw a shape based on user input.
Maths Challenge Can you write a program that asks the user for two numbers, adds
them together and displays the result? Ask for a number Create a variable Set the variable to that number
Can you write a program that asks the user for the length of a rectangle and the height and works out the area?
Area of a rectangle is height x length
Can you do the same for Speed
Volume of a cube
Area of a Circle
Find what the formula is online.
Pi = 3.14
Task
You are going to create a program that asks the user to input how many sides they would like their shape to have and then you are going to draw a shape with that many sides.
Angles
There are 360 in a circle.
What angle did you have to turn when you drew a square. What is 90 multiplied by 4?
What angle did you have to turn when you drew your triangle? What is 120 multiplied by 3.
So to figure out what angle to turn you need to divide 360 by how ever many sides you have.
Task Ask how many sides the user wants in their
shape.
If they want 4 sides how often are you going to have to repeat your programme. Think back to when you made your square and triangle.
Add a repeat that will repeat the program as many times as they have said. You will need to drag their answer onto the if.
Get Going Combine these actions to create your programme to draw a
shape.
What do you need to do to get it to actually draw the shape?
Extension: Can you get the sprite to come back to the centre every time the
green flag is pressed?