0% found this document useful (0 votes)
36 views11 pages

Use of Variable

The document discusses variables, program plans (also called algorithms), and conditional loops. It provides examples of using a variable to store a user's answer and creating a program plan with inputs, processes, and outputs to ask and check answers to math questions. It then discusses improving the plan to ask random questions and adding a conditional loop that repeats questions until the user inputs "Y" to stop.

Uploaded by

hussain korir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views11 pages

Use of Variable

The document discusses variables, program plans (also called algorithms), and conditional loops. It provides examples of using a variable to store a user's answer and creating a program plan with inputs, processes, and outputs to ask and check answers to math questions. It then discusses improving the plan to ask random questions and adding a conditional loop that repeats questions until the user inputs "Y" to stop.

Uploaded by

hussain korir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Use of Variable

 Variables stores a value, You give every variable a name, then you can use the
value in your program.
 Two variable are mentioned in the program plan
 In scratch there is a ready variable called ”Answer” you can ask a sprite a
question then the users answer is stored in the variable answer.

Program Plan
 For you to become a good programmer ,you must make a program plan.
 A program plan sets out the steps to solve a problem,

 Another name / word for plan to solve a problem is called Algorithm.


 A program plan sets out , the inputs and outputs of a program, it also
set the process to be carried out by the computer such as calculation .
Here is a program plan
 Input: Prompt with a question (what is 7
times 5) ‘Input ther users answer’
 Process: Stores the solution to the question .
 ( It compares the users answer to the
solution)
 Output: If the answer matches the solution
output ”you got it right”
Else, output “You got it wrong”
 >> You can also make a variable called
“solution” this will store your answers or
the correct solution to the Question.
>>Click on “make a variable”
 >>the variable will be ticked this means it
will show on the main screen.
Ask a random question
 This program will a low the user to practice the 7 times table.
 In the last lesson we created the program that asked a question.
 In this program we will change the program so that it can ask different
“seven times” question every time you run it,

 Our Improved Plan


Input: Make a random number
Ask “what is 7 times random number?”
 Process: Calculate the ‘solution’ to the question Compare the users answer to
the solution. do they Match?
 Output: If the answer matches the solution, Output ” You got it right”
 Else, output “you got it wrong”
Conditional loop
 In the previous lesson we created a program with a counter loop , it
loops exactly 10times,the has ten question.
 Before every test question the program will ask the user if they want to

stop the test.


 If the user types ”Y” (for yes) the loop will stop.

>> This type of loop is called conditional loop.


>> A conditional loop is controlled by a logical test,
>> A logical test compares two values . It give the result True or False.

Change the Plan


Here is the new program plan.
Input: Ask the question and get the users answer.
Process : Calculate the solution to the question.
Output: If ‘answer= Solution’ output you got it right!’
Else , you got it wrong!’
Input: Ask ‘ Do you want to stop’
 Go to the top of the loop
>>You must put the Question ‘ do you want to stop’ inside the loop , that
gives the user the chance to stop after every question,
Create the Test
 Your program will ask the user if they want to stop ., if the user types ‘y’
the program will stop.
>> This block compare the user answer to the letter ‘Y’.
Make this test block
Conditional loop
 Here the block that makes the
conditional loop.

 This type of conditional loop is called


Repeat until loop.it starts with a logical
test ,the command inside the loop will
repeat until the logical test is True.
>> Add the logical test at the top of the
loop.
>> Add the Question ‘Do you want to
stop?’ inside the loop.
**** The loop will repeat itself until the
answer to the question is ‘Y’

You might also like