Advertisement
amigojapan

and or not and equals in scratch and 3dpl

Mar 30th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. operators AND OR NOT && || ! == !=     what is = vs == if statements else statement elseif switch statements  
  2. First teach AND OR and NOT gates in http://logic.ly/demo
  3. show how they work with simple switches and lightbulb
  4. explain that in when we use an AND OR or NOT expression in any langauge, they eventually get put thru an AND OR or NOT gate in the CPU
  5. (up to here it is done)
  6.  
  7. Second in scratch, make examples of AND OR and NOT,  perhaps make scratch say something depending on the resurlts of ADN NOT and OR
  8. like for example say true when true AND ture   , say true when flase OR ture , say false when false of false
  9. http://beta.scratch.mit.edu/projects/10067409/
  10.  
  11.  
  12. explain variables and the difference between = and ==
  13. have 3dpl draw a red cube if varibale a==5 else draw a green cube... change the value of a so that the user can see the operations taking place
  14. Mention that in these examples, a green cube means true, and a red cube means false
  15. Explain that // is a comment in C style languages and { opens a block of code } closes the block
  16. 3dpl Declarations:
  17. qb("ACube",0,0,0);//makes a cube
  18. var a=5;//in this case = is an assignbment, put 5 into a. change 5 to 3 to see the cube change from green to red
  19. if(a==5) {//in this case == is a comparison, which is true if a is equal to 5 and is false if a is not equal to 5
  20.   cl("ACube", Color.green);//colors a cube green
  21. } else {
  22.   cl("ACube", Color.red);//colors a cube red
  23. }
  24.  
  25. explain !=, explain that the '!' sign is usually called NOT in C style langauges
  26. 3dpl Declarations:
  27. qb("ACube",0,0,0);//makes a cube
  28. var a=5;//change 5 to 3 to see the cube change from red to green
  29. if(a==5) {//in this case != is a comparison, which is true if a is not equal to 5 and is false if a is not equal to 5
  30.   cl("ACube", Color.green);//colors a cube green
  31. } else {
  32.   cl("ACube", Color.red);//colors a cube red
  33. }
  34.  
  35. Third: in 3dpl   explain the same things, but now with C style syntax
  36. and explain just plain not operator !
  37. 3dpl Declarations:
  38. qb("ACube",0,0,0);//makes a cube
  39. var a=1;//change 1 to 0 to see the cube turn from red to green
  40. if(!(a==1)) { //when a is 1 (a==1) is true,   so by saying NOT ture,  it actually ends up being false, so we should get a red cube
  41.   cl("ACube", Color.green);//colors a cube green
  42. } else {
  43.   cl("ACube", Color.red);//colors a cube red
  44. }
  45.  
  46. && AND
  47. 3dpl Declarations:
  48. qb("ACube",0,0,0);//makes a cube
  49. var a=1;//try a=0 and b=1, also a=1 and b=0, also b=0 and a=0
  50. var b=1;
  51. if((a==1)&&(b==1)) {//when a is 1 (a==1) is true,  when b is 1 (b==1) is true, so (a==1) AND (b==1) is true
  52.   cl("ACube", Color.green);//colors a cube green
  53. } else {
  54.   cl("ACube", Color.red);//colors a cube red
  55. }
  56.  
  57. || OR
  58. 3dpl Declarations:
  59. qb("ACube",0,0,0);//makes a cube
  60. var a=1;//try a=0 and b=1, also a=1 and b=0, also b=0 and a=0
  61. var b=0;
  62. if((a==1)||(b==1)) {//when a is 1 (a==1) is true,  when b is 0 (b==1) is false, so (a==1) OR (b==1) is true
  63.   cl("ACube", Color.green);//colors a cube green
  64. } else {
  65.   cl("ACube", Color.red);//colors a cube red
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement