Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 14 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
14
Dung lượng
327 KB
Nội dung
Section Calculations National 4/5 Scratch Course What you should know after this lesson • • • • How scratch stores numbers How to use variables in calculations What operators The importance of sequence in calculations Variables These are storage locations in RAM, controlled by the programming language What types of data might we need to use with our programs? The main ones we will be using are – Numeric – String Numeric • Are used for calculations • If you need to use a piece of data in a calculation you should use a number variable Scratch Variables The scratch language is able to work out the type of variable we are using and as a result it only has the one type of variable Click on the variables tab Click “Make a variable” Type the name you want to use for the variable Displaying Variables • We can get any sprite to speak by using the say block from inside looks • Variables can be displayed on the stage for example to display information useful to the user Calculations • For this task we are going to add two numbers together • Create a new scratch project and add two new variables called first and second • Add the script shown below Copy the program into your jotter and answer What does the program do? Why we need First & Second? Other Operators • Copy the blocks on the right into your jotter • Write beside each one what it does • How could we bigger calculations? Combining Operators • Scratch Operator blocks (+*/) can be combined to make more complex calculations • Simply drag a block into the white box • Remember the BODMAS rules from maths • • • • • • Brackets () Of ^ Division / Multiplication * Addition + Subtraction - Task • • Calculate the answer to the following problems, write the answers in your jotter (you can use a calculator) Enter the calculations into scratch and check your answers 5+4 5*4 5+4-3 34+3*6 (34+3)*6 40/5 + 4+40/5 How can we get it to display the full sum as the answer? • You can add join to join to make a longer sentence • To drag the whole script block drag the lowermost block • Edit the program to subtract, multiply & divide Save it in your network area Assignment of variables • Variables can be assigned values using the set block • Variables can be assigned the results of a calculation as well as the answer to an ask block Review Questions Copy and answer these questions in your jotter Where does scratch store numbers? What is assignment? What arithmetic operators do? Why is the sequence of calculations important? Tasks Create scratch programs to the following (save each in your network area) Calculate the area of a rectangle Calculate the square of a number Calculate the sum of three numbers Calculate the average of three numbers ... answers in your jotter (you can use a calculator) Enter the calculations into scratch and check your answers 5+4 5*4 5+4 -3 34 +3* 6 (34 +3) *6 40/5 + 4+40/5 How can we get it to display the full sum... Numeric – String Numeric • Are used for calculations • If you need to use a piece of data in a calculation you should use a number variable Scratch Variables The scratch language is able to work out... each one what it does • How could we bigger calculations? Combining Operators • Scratch Operator blocks (+*/) can be combined to make more complex calculations • Simply drag a block into the