Class VI Coding Student Handbook PDF
Document Details
Uploaded by Deleted User
null
2021
CBSE
null
Tags
Summary
This handbook provides an introduction to coding for class VI students, emphasizing computational thinking, problem-solving, and design thinking. It utilizes real-world examples and the MakeCode platform. This document aims to make learning engaging through practical examples and activities.
Full Transcript
INTRODUCTION TO CODING GRADE VI Student Handbook Version 1.0 INTRODUCTION TO CODING GRADE VI Student Handbook ACKNOWLEDGEMENT Patrons Sh. Ramesh Pokhriyal 'Nishank', Minister of Human Resource Development,...
INTRODUCTION TO CODING GRADE VI Student Handbook Version 1.0 INTRODUCTION TO CODING GRADE VI Student Handbook ACKNOWLEDGEMENT Patrons Sh. Ramesh Pokhriyal 'Nishank', Minister of Human Resource Development, Government of India Sh. Dhotre Sanjay Shamrao, Minister of State for Human Resource Development, Government of India Ms. Anita Karwal, IAS, Secretary, Department of School Education and Literacy, Ministry Human Resource Development, Government of India Advisory Editorial and Creative Inputs Mr. Manuj Ahuja, IAS, Chairperson, Central Board of Secondary Education Guidance and Support Dr. Biswajit Saha, Director (Skill Education & Training), Central Board of Secondary Education Dr. Joseph Emmanuel, Director (Academics), Central Board of Secondary Education Sh. Navtez Bal, Executive Director, Public Sector, Microsoft Corporation India Pvt. Ltd. Sh. Omjiwan Gupta, Director Education, Microsoft Corporation India Pvt. Ltd Dr. Vinnie Jauhari, Director Education Advocacy, Microsoft Corporation India Pvt. Ltd. Ms. Navdeep Kaur Kular, Education Program Manager, Allegis Services India Value adder, Curator and Co-Ordinator Sh. Ravinder Pal Singh, Joint Secretary, Department of Skill Education, Central Board of Secondary Education ABOUT THE HANDBOOK Coding is a creative activity that students from any discipline can engage in. It helps to build computational thinking, develop problem solving skills, improve critical thinking and exposure to real life situations to solve problems in various realms. Therefore, CBSE is introducing ‘Coding’ as a skill module of 12 hours duration in classes VI-VIII from the Session 2021-2022 onwards. The idea is also to simplify the coding learning experience by nurturing design thinking, logical flow of ideas and apply this across the disciplines. The foundations laid in the early years will help the students to build the competencies in the area of AI, data sciences and other disciplines. CBSE acknowledges the initiative by Microsoft India in developing this coding handbook for class VI students. This handbook introduces concepts of coding and computational thinking using real life examples and block coding with open source MakeCode platform. It uses gamified learning approach to make learning experience more engaging. The book is intuitive with practical examples of theoretical concepts and applied exercises. There are mini projects that students can work on. Additionally, the handbook also focuses on creating exposure to ethics of coding and promotes empathy among students by activities curated to demonstrate empathy and sensitivity. The purpose of the book is to enable the future workforce to acquire coding skills early in their educational phase and build a solid foundation to be industry ready. RESOURCES FOR STUDENTS Minecraft education edition Minecraft education edition is a game-based learning platform that promotes creativity, collaboration, and problem-solving in an immersive digital environment. This platform provides a fun way of learning coding and design thinking concepts. Visit https://education.minecraft.net/ for more details. MakeCode Microsoft MakeCode is a free, open source platform for creating engaging computer science learning experiences that support a progression path into real-world programming. It brings programming to life for all students with fun projects, immediate results, and includes both block and text editors for learners at different levels. Visit https://www.microsoft.com/en-us/makecode for more details. GitHub GitHub is a storehouse where you can manage and collaborate on your code. It helps to maintain different versions of the code easily. GitHub Student Developer Pack gives students free access to the best developer, web development, gaming and many other tools at no cost enabling practical learning. Sign up for the GitHub Student developer pack here https://education.github.com/discount_requests/student_application?utm_source=2 021-06-11-cbse TABLE OF CONTENTS Table of Contents........................................................................................... I Ethical practices in coding...............................................................................1 Introduction to Coding....................................................................................2 1.1 What will you learn in this chapter?.......................................................2 1.2 How do traffic lights work?....................................................................2 1.3 Where else do we see applications of coding?............................................2 1.4 What exactly is coding?........................................................................2 1.5 What is a programming language?..........................................................3 1.6 Quiz Time..........................................................................................4 1.7 What did you learn in this chapter?........................................................5 Algorithms With Block Coding..........................................................................6 2.1 What will you learn in this chapter?.......................................................6 2.2 Searching for a word in the dictionary.....................................................6 2.3 Flowcharts.........................................................................................7 2.3.1 What is a Flowchart?......................................................................7 2.3.2 Symbols used in a flowchart............................................................7 2.3.3 Benefits of using a flowchart............................................................8 2.4 Activity: Profit and loss with flowcharts...................................................8 2.5 Pseudocode........................................................................................8 2.5.1 What is a Pseudocode?...................................................................8 2.6 Activity: Profit and loss with pseudocode.................................................9 2.7 Getting started with block coding...........................................................9 2.8 Quiz time......................................................................................... 13 2.9 What did you learn in this chapter?...................................................... 18 Variables using block coding.......................................................................... 19 3.1 What will you learn in this chapter?..................................................... 19 3.2 What are variables?........................................................................... 19 I 3.3 Naming variables.............................................................................. 19 3.4 Data types in variables....................................................................... 20 3.5 Performing Operations on Variables...................................................... 23 3.6 Activity: Addition operation using block coding....................................... 24 3.7 Quiz time......................................................................................... 34 3.8 What did you learn in this chapter?...................................................... 36 Control with conditionals............................................................................... 37 4.1 What will you learn in this chapter?..................................................... 37 4.2 Arranging blocks............................................................................... 37 4.3 And operator.................................................................................... 37 4.4 OR Operator..................................................................................... 38 4.5 NOT Operator................................................................................... 39 4.6 Combining logical operators................................................................ 39 4.7 Quiz time......................................................................................... 40 4.8 Relational operators........................................................................... 40 4.9 Activity: Are you a teen?..................................................................... 40 4.10 Activity: Dynamic backgrounds......................................................... 41 4.11 Nested Conditional Statements......................................................... 46 4.12 Activity: The remainder problem........................................................ 46 4.13 Quiz time...................................................................................... 50 4.14 What did you learn in this chapter?................................................... 53 Loops using block coding............................................................................... 54 5.1 What will you learn in this chapter?..................................................... 54 5.2 Introduction to loops......................................................................... 54 5.3 Increment Loops............................................................................... 54 5.4 Different types of loops....................................................................... 55 5.5 Activity: Building a music player.......................................................... 58 5.6 Entry Criteria................................................................................... 61 5.7 Exit Criteria..................................................................................... 61 5.8 Break Statement............................................................................... 62 5.9 Continue Statement........................................................................... 63 5.10 Activity: A tale of two villages............................................................ 63 II 5.11 Quiz time...................................................................................... 68 5.12 What did you learn in this chapter?................................................... 72 References.................................................................................................. 73 III ETHICAL PRACTICES IN CODING As you build capabilities around coding, you will be equipped to build software on your own, which will have an impact on society in general. So, it is very important to adhere to ethical practices while building your own code. Below are some practices you must remember as you keep learning to code. Contribute to society and human wellbeing You must limit negative results of software, including dangers to safety, health, personal security, and privacy Do consider the aftereffects of the software. Ensure your Code respects diversity and is utilized responsibly with social issues in mind In addition to this, promote environmental sustainability both locally and globally Avoid harm to others Your code should not cause physical or mental injury, unjustified destruction to property or information Avoid unjustified damage to reputation and environment 1|Page INTRODUCTION TO CODING traffic signals to show different colors. Sometimes it is even smarter, where the 1.1 What will you learn in this code detects congestion based on chapter? sensors and maximizes efficiency by only functioning when traffic is present. Do you want to know what code is? How is code applied in real life, and how does 1.3 Where else do we see it impact our day-to-day activities? applications of coding? Welcome to the introductory section on coding. Most of us knowingly or unknowingly Here you will learn: engage with programming, be it inside our homes or outside. Coding, in the Real world application of coding modern world, can be seen on the How coding impacts our daily lives streets, at the schools, at the local What exactly is coding in context grocery stores, etc. of computer science Some of the practical examples of coding in the real world are: 1.2 How do traffic lights work? Interaction with bar-code scanners at shopping store Automatic control of traffic using Have you ever wondered traffic lights how traffic signals Booking movie, bus, train, flight function? The lights cycle tickets online through green, yellow, Printers and red at regular Computer software we use like intervals to control road web browser, Word etc. intersections' traffic flow. They prevent Video games and animations for accidents and help to avoid congestion entertainment on the roads. However, how do the traffic lights 1.4 What exactly is coding? change automatically? Few lines of code running in the Coding, also referred to as background drive the traffic lights. At programming, is creating instructions regular intervals, the code changes the that can be executed on a computer to 2|Page perform a specific task or achieve a particular result. Coding is just like solving a math problem. There may be many ways to solve a problem. Similarly, there could be more than one way to write code for the same task. Just like solving any other problem, some coding approaches are more efficient than others. Think you are playing a video on your smartphone. Your phone is like a computer that needs to be instructed on what to be done. The app playing the video provides this instruction. This video-playing app is an example of coding. But how does the app communicate the instructions to the Some of the most frequently used phone? It does via a programming ones are: language. In the next section, we will get Python to know more about programming Java languages. JavaScript C# 1.5 What is a programming R C++ language? C F# Think about how we communicate with COBOL people around us? Language is our primary means of communication for all Syntax is a set of rules that we need to human interactions. Similarly, we can follow when we write a computer interact with computers via a language program. that computers understand. This There are hundreds of programming language is called a programming language. Using programming languages used around the world. And new ones are getting developed all the languages, we can provide instructions to a computer to perform a set of time. Every programming language has activities. These sets of instructions are its own syntax. But all programming languages have one common thing: they also called programs. Like any other language that has grammar, are eventually converted into a language that the computer will understand. programming languages have syntax. 3|Page Throughout this chapter, we will learn know a little bit about coding and its about different programming techniques applications, let us try to do some and how to apply them. Now, that we exercises. 1.6 Quiz Time Question 1 For a given problem, there is always only one way to write a program Option 1 True Option 2 False Question 2 Pin authentication for ATM card transaction is an example of programming Option 1 True Option 2 False Question 3 Code is a set of instructions that can be executed on a computer to perform a specific task Option 1 True Option 2 False Question 4 Which among the below are examples of programming in real life? Option 1 Robots Option 2 Computer Games Option 3 Self-drive cars Option 4 All the above Question 5 Which among the below is not an example of programming language? Option 1 Python Option 2 English Option 3 JavaScript 4|Page 1.7 What did you learn in this chapter? So, we are at the end of the introductory chapter for coding. By now, you should understand How coding is being utilized in everyday life to perform complex tasks in an easy manner What are the real-life applications of coding? What is exactly meant by the term coding in context of computer science? Now you know names of some of the most popular programming languages 5|Page ALGORITHMS WITH BLOCK CODING how does he find that word 'proxy' in the 2.1 What will you learn in this chapter? Now that we already have a fair understanding of coding applications in real life, let us understand how to solve a coding problem in detail. By the end of this chapter, you will learn: What does the term algorithm mean? What is a flowchart? dictionary? Applications of flowchart Get introduced to pseudocode To achieve this, he first needs to find the dictionary section with the first letter of the word, which in this case is 'p.' Then, 2.2 Searching for a word in the within the list of words starting the first dictionary letter 'p', he needs to find the section having the second letter of the word 'r'. While reading a book in a school library, He needs to do this operation again with Mukesh comes across a word say 'proxy' the third, fourth & fifth letters until he whose meaning he does not know. So finally reaches the word 'proxy' in the how does he find out the meaning of this dictionary & then finds its meaning. word? In other words, Mukesh needs to follow The simple answer to this is that a set of steps to complete the task of finding the meaning of a word. Mukesh searches for the meaning of the word 'proxy' in a dictionary. However, Similarly, before writing a program code there are many words in a dictionary. So for a given problem in computer science, 6|Page it is essential to devise a set of steps to be followed to solve the problem successfully. This set of steps is called an algorithm. Thus, in computer science, an algorithm is defined as the step-by-step plan to solve the problem for a given problem statement. 2.3 Flowcharts 2.3.1 What is a Flowchart? A flowchart is a diagrammatic representation of the step-by-step plan to be followed for solving a task/problem statement. This diagrammatic representation is made up of shapes like boxes, diamonds, parallelograms, circles, ellipses connected by arrows. Each shape acts as a step in the solution, and the arrows represent the direction of flow among the steps. 2.3.2 Symbols used in a flowchart 7|Page 2.3.3 Benefits of using a flowchart The focus is mainly on including all Some of the benefits of using a flowchart are: 1. It helps to explain your approach towards solving a problem 2. The flowchart helps in bringing in visual clarity to a problem, so it helps in practical problem solving 3. Once you build a flowchart, this remains as documentation of the code you are about to build. If you need to come back and understand the code, you can refer to the flowchart. 2.4 Activity: Profit and loss with flowcharts the essential steps to solve the Shown in the image is a flowchart that problem. Thus, the solution tends to takes two inputs, namely cost price and be comprehensive selling price. It then calculates profit or Reviewers can quickly review the loss depending on the values and prints pseudocode & verify if the steps will the same. generate the desired outcome While writing pseudocode, you can focus on all possible scenarios. So, this helps you understand the 2.5 Pseudocode potential problems that might come up later 2.5.1 What is a Pseudocode? Since you are not worried about coding syntax, you can concentrate In computer science, pseudocode is on the actual problem used to describe the steps followed in an Writing pseudocode will help writing algorithm via simple human- your code much easier comprehensible language. Thus, it has Works as documentation of the code. no syntax of any programming language So even a layman with no coding and can be understood by a layman. The knowledge can refer to the advantages of representing the solution pseudocode as pseudocode are multifold: 8|Page 2.6 Activity: Profit and loss programming and learn coding concepts with pseudocode easily. MakeCode Arcade is one of the platforms to perform block-based programming. Now that we have a fair understanding of flowcharts and pseudocode, let us try Using arcade, solution to a problem to implement the same profit and loss statement can be implemented using problem using pseudocode. various categories of blocks and the results can be seen side by side on the same screen. Program starts The different categories of blocks will be Read Cost Price (CP) explored in the upcoming chapters. Read Selling Price (SP) Note: Minecraft is just one of the If (SP > CP) then platforms for block coding. You can use Profit = SP – CP many similar platforms available online for block coding like – Scratch Print Profit (https://scratch.mit.edu/), Code.org Else (https://code.org/) etc. Loss = CP – SP We will now start a simple block coding exercise on Minecraft platform. Print Loss Open the URL Program ends https://arcade.makecode.com in your favorite web browser. 2.7 Getting started with block coding Microsoft MakeCode is a framework for creating interactive and engaging programming experiences for those new to the world of programming. The main objective of MakeCode is to bring programming to the forefront in a way that is more alluring and friendly. To achieve this, MakeCode utilizes the blocks programming model to let those who are new to the world of 9|Page 10 | P a g e 11 | P a g e 12 | P a g e Congratulations, you have created your first block code program! Now let us do a quiz. 2.8 Quiz time Objective type questions 1. Select a word from column A and place it in a cell on column B such that its definition matches in cells of column C A B C Writing steps involved to solve a problem in a Algorithm human-understandable language Block based coding Flowchart platform Define step by step plan Pseudo Code to solve a problem statement Solution to a problem Arcade presented as a diagram Below is a flowchart to calculate profit and loss. Answer questions 2 to 4 based on the flowchart. 13 | P a g e Question 2 Jyoti owns a toy shop. She bought a toy for Rs 325 and sold it for Rs. 375. Which one from the below is correct? Option 1 She made a loss of Rs. 50 Option 2 She made a profit of Rs. 50 Question 3 Raju buys a pen for Rs 15, and after some time, he sells it for Rs 10. Which one from the below is correct? Option 1 He made a loss of Rs. 5 Option 2 He made a profit of Rs. 5 Question 4 Ram buys a table for Rs 500, he sells it for Rs 550. Which one from the below is correct? Option 1 He made a loss of Rs. 50 Option 2 He made a profit of Rs. 50 14 | P a g e Question 5 Which of the following is not an advantage of a flowchart? Option 1 Efficient coding Option 2 Systematic testing Option 3 Improper documentation Option 4 Better communication Question 6 The following box denotes. Option 1 Initialization Option 2 Decision Option 3 Input / Output Option 4 Connectors Question 7 What is a flowchart? Option 1 A specific programming language Option 2 A text-based way of designing an algorithm Option 3 A bullet point list of instructions Option 4 A diagram that represents a set of instructions Question 8 What shape represents the start and end of a flowchart? Option 1 Square Option 2 Diamond Option 3 Oval Option 4 Circle Short Answer questions 1. What is a pseudocode? 2. What are the benefits of using flowcharts? 3. What is a flowchart? 15 | P a g e Higher Order Thinking Skills (HOTS) 1. Below is a flowchart on how to calculate if a number is even or odd. Write the corresponding pseudocode for the problem. Note: Modulus operator (%) is used to find the remainder of two number. 2. The below pseudocode prints "Above average marks" if the average marks in three subjects are greater than 75. If average marks are less than or equal to 75, then it prints "Below average marks". Draw the corresponding flowchart for the problem. 16 | P a g e Program starts Read marks for subject SubA Read marks for subject SubB Read marks for subject SubC Calculate AverageMarks = (SubA + SubB + SubC)/3 Print AverageMarks If (AverageMarks > 75) Print (“Above Average Marks”) Else Print (“Below Average Marks”) Program ends Applied Project Create a flowchart based on your normal school day. Here are some guidelines: Getting ready for school Look at your timetable and pack your school bag If PE is there packing your PE uniform and shoes At school Attend the morning session with subjects Math, English and science A decision on what to play during recess After reaching home Have snacks Depending on the day, choose the class you have to attend. Monday-Karate, Tuesday-Math Class, Wednesday and Thursday Free day, Friday-Karate 17 | P a g e 2.9 What did you learn in this chapter? By now you should have a basic understanding about algorithms, flowchart & pseudocode You have also practiced following a step by step approach to solve a problem using block-based programming You got oriented to MakeCode platform which we will use throughout the course 18 | P a g e VARIABLES USING BLOCK CODING program. Any defined variable cannot be 3.1 What will you learn in this accessed beyond its scope. chapter? 3.3 Naming variables What are variables? How to name variables? Commonly used data types Performing operations on variables 3.2 What are variables? In programming, variable is a packet in which we can store data. These packets As we have understood till now, variables are basically like nouns in a programming language. Every variable in a program is unique. To identify these variables uniquely, user needs to allocate them a unique name. This name acts as an identifier for that variable. In programming, a user is not allowed to use the same name of a variable more can be named and referenced and can be than once. used to perform various operations. To perform a mathematical operation, you Naming variables make it to easier to call can declare two variables and perform them while performing operations. The the operation on them. name of a variable also suggests what information the variable contains. Scope of a variable refers to the part of the code where the variable can be used. You can refer to the example before for The scope or accessibility of the better understanding about variables: variables defined in a program depends If variable named as "a" is equal to 2 and on where you have declared it in each variable named as "b" is equal to 2, 19 | P a g e performing add operation on "a" and "b" integer variable and assign it a non- is going to result into an output as "4". integer value, the program returns an error. Variables of the integer data type are only capable of holding single values. 3.4 Data types in variables These variables are not capable of holding a long list of values. Variables are the values that are acted Floating Point Number Data Type upon. Every value needs to be assigned to a specific data type to make the Floating-point numbers are used to variable more readable by a computer. store decimal values. They hold real Data type identifies what the type of data numbers with decimal values. that the declared variable can hold is. Depending on the programming Thus, it indirectly helps the computer to language, the syntax to declare floating- understand what operations need to be point variable changes. performed on those variables. The declaration of a variable in a program contains two components – the name of the variable and its type. Example of declaring a floating-point Let us now understand what are the number variable: common data types that we can use in float a = 1.1; programming: Integer There is another type of floating-point Floating-point number number known as a "double" data type, Character which is used to store even bigger String values. Boolean Integer Data Type Integer data type variables store integer Example of a double value: values only. They store whole numbers which have zero, positive and negative double a = 8.999999999 * values but not decimal values. Multiple 7.66666666666; programming languages support different syntax to declare an Integer variable. If a user tries to create an Character Data Type Example of declaring an Integer Character type variables are used to variable: store character values. Syntax of int a = 2; declaring a character variable is specific to the programming language that you 20 | P a g e are using. If a user tries to create a data types for variables as per program character variable and assign it with a needs and assign variables an non-character value, the program will appropriate data type. throw an error. The character data type Boolean is a subtype of integer data is the smallest data type in type. It stores true and false where true programming. means non-zero and false means zero. Any character values can be declared as a char variable. Example of declaring a Boolean variable: Example of declaring a character bool a = true; variable: Any Boolean variable holding Boolean char a = ‘w’; value can be declared as Boolean. String Data Type Note: In some programming languages like python, there is no command to To extend the character data type, a user may have a requirement to store and Example of declaring variables in perform an operation on a sequence of python characters. In such cases, the String data type is present to fit the gap. The a=5 String data type stores value in a b = “Hello” sequence of characters i.e. in String format. declare variables. A variable is created Example of declaring a String the moment you first assign a value to it. variable: If you want to specify the data type of variable this can be done using casting. String a = “I am a String Variable”; Example: y = str(7) Any string value can be declared as a z = int(7) string variable. a = float(7) y will be saved as ‘7’ Boolean Data Type z will be saved as 7 There is a subtype of Integer Data Type a will be saved as 7.0 called "Boolean Data Type", which stores values in Boolean type only i.e. "true" or "false". Users can choose between the 21 | P a g e Let us now apply different data types in Function Main a pseudocode. We will first declare Declare Integer i = 1234567890 ---------------------------------------------------------- Float f = 1.234 Declare Integer i Char c = c Declare Float f String s = string Declare Char c Boolean b = true Declare String s different types of variables, followed by Declare Boolean b assigning them to appropriate values. Assign Finally, we will use the variables by outputting their values. ----------------------------------------------------- Assign i = 1234567890 Assign f = 1.234 Assign c = ‘c’ Assign s = "string" Assign b = true Use ------------------------------------------------------ Output "Integer i = " & i Output "Float f = " & f Output "Char c = " & c Output "String s = " & s Output "Boolean b = " & b End The output from the above pseudocode will be like below. Note: The syntax is different for different data types in other programming languages. 22 | P a g e In python string variables can be numeric expression. The basic operators declared either by single quotes or for performing arithmetic are the same double quotes or triple quotes. in many computer languages: Below are some rules for naming a Addition variable in python: Subtraction Multiplication A variable name cannot start with Division a number, it must start with an Modulus (Remainder) alphabet or the underscore (_) sign Assignment operators Variable name is case sensitive. Sum and sum are different Assignment operators are used to assign variables values to variables A variable can only contain alpha Different assignment operators are numeric characters and shown below: underscore “=”: This operator is used to assign the value on the right to 3.5 Performing Operations on the left variable. Variables Example: a=50 “+=”: This operator assigns the After declaring the data types in result to the variable on the left programming, now let us move ahead after adding the current value of and understand what operations we can the variable on left to the value on perform on the data types and how do the right. we perform these operations: Example: x += y It can also be written as x = x + y Arithmetic Operations “-=”: This operator assigns the result to the variable on the left after subtracting the value of the variable on right from the current value on the left. Example: x -= y It can also be written as x = x - y “*=”: This operator assigns the result to the variable on the left after multiplying the current value of the variable on left to the value on the right. Example: x *= y An arithmetic operation combines two or It can also be written as x = x * y more numeric expressions using the “/=”: This operator assigns the Arithmetic Operators to form a resulting result to the variable on the left 23 | P a g e after dividing the current value 3.6 Activity: Addition of the variable on left from the operation using block value on the right. coding Example: x /= y It can also be written as x = x / y An addition arithmetic operation is used Increment operator to add the values stored in two variables. Increment operator adds one to the Like the way we add values in value. mathematics, we can store values in different variables and perform an Example: A=8 additional operation. The addition of B=A++ these variables is displayed as an output of the program. The output of B will be 9 (A+1) For example, performing add operation A++ has the same meaning as A=A+1 on a variable "a" holding value "3" and a Decrement operator variable "b" holding value "4" will result in an output "7". To understand this Decrement operator subtracts one from arithmetic operation better, let us the value. understand how to implement it practically in programming. For this, we Example: A=8 are going to take example of platform B=A-- https://arcade.makecode.com/. Let us refer to the steps below understand The output of B will be 7 (A-1) more in details. A-- has the same meaning as A=A-1 24 | P a g e 25 | P a g e 26 | P a g e 27 | P a g e 28 | P a g e 29 | P a g e 30 | P a g e 31 | P a g e 32 | P a g e Subtraction Division Subtraction arithmetic operation is used Division arithmetic operation is used to to subtract the values stored in one divide the value stored in one variable by variable from another variable. Like the the value stored in another variable. Like way we subtract values in mathematics, the way we divide values in we can store values in different variables mathematics, we can store values in and perform subtraction operations. different variables and perform division Subtraction of these variables is operations. Division of these variables is displayed as an output of the program. displayed as an output of the program. For example, performing subtraction For example, performing division operation on a variable "a" holding value operation on a variable "a" holding value "10" and a variable "b" holding value "8" "2" and a variable "b" holding value "2" will result in an output "2". will result in an output "1". Multiplication Modulus (Remainder) Multiplication arithmetic operation is Modulus operator (%) calculates the used to multiply the values stored in two remainder when two variables are variables. Like the way we multiply divided. Please note that this operation values in mathematics, we can store can only be performed on integer and values in different variables and perform float variables in Python. multiplication operations. Multiplication For example, performing modulus of these variables is displayed as an operation on a variable "a" holding value output of the program. "9" and variable "b" holding value "3" will For example, performing multiply result in an output "0" as there is no operation on a variable "a" holding value remainder in this operation. "2" and a variable "b" holding value "2" will result in an output "4" 33 | P a g e 3.7 Quiz time Objective Type Questions Question 1 An integer data type can hold decimal values. Option 1 True Option 2 False Question 2 Variables must be defined with a name and a data type before they can be used Option 1 True Option 2 False Question 3 Which of the following is not a valid variable name in python? Option 1 _test Option 2 11test Option 3 Test13 Option 4 Test_2 Question 4 Fill in the blanks to declare sum equal to a + b (int _ = a __b) Option 1 Sum,+ Option 2 Var,- Option 3 Bool,+ Option 4 Add,+ Question 5 Which of the following data type is used to store decimal values? Option 1 Integer Option 2 Float Option 3 Boolean Option 4 String Question 6 How many times should a data type be mentioned for a variable Option 1 Everywhere the variable is used 34 | P a g e Option 2 When entering variable’s value Option 3 When printing a variable’s value Option 4 Only once; When declaring the variable Question 7 Which of the following symbol is used to multiply variables? Option 1 * Option 2 + Option 3 x Option 4 % Question 8 What is the alternative of y=y+9 Option 1 y=x+9 Option 2 y+=9 Option 3 y-=9 Option 4 x=+9 Question 9 Y++ has the same meaning as Option 1 Y=Y+1 Option 2 X=+2 Option 3 y-=6 Option 4 X=x-5 Question 10 Which of the following symbol is used to find the remainder? Option 1 * Option 2 + Option 3 x Option 4 % Short Answer Questions 1. Define variables in programming 2. Can we declare two variables in a program with the same name? 3. What are the common Data Types in programming? 4. Name a data type that can store exponential values 5. Write the pseudocode to perform an addition operation on two variables in a program 35 | P a g e Higher Order Thinking Skills (HOTS) 1. Create a flowchart to perform different mathematical operation (Multiplication, Subtraction, Addition, Division) on two or more variables. 2. Create a project in https://arcade.makecode.com/ to perform Modulus operation on two variables in a program. Applied Project Using block coding, create your normal school day (Monday to Friday). Here are some guidelines: Getting ready for school Look at your timetable and pack your school bag If PE is there packing your PE uniform and shoes At school Attend the morning session with subjects Math, English and science A decision on what to play during recess Attend the afternoon session subjects Lunch Break PE Class After reaching home Have snacks Depending on the day choose the class you must attend. Monday-Karate, Tuesday-Math Class, Wednesday-Swimming and Thursday- Chess, Friday-Dance (You can use variables to define the class you have to attend) 3.8 What did you learn in this chapter? What are variables and how they are used in programming Ways of naming variables. Different data types in programming and its usage Various operations that we can perform of different data types in programming 36 | P a g e CONTROL WITH CONDITIONALS Similarly, every day we take many decisions depending on our situation. 4.1 What will you learn in this For instance, when it is cold outside, we chapter? wear warm clothes, otherwise, we don't. What are conditions and how to Logical operators are fundamental apply them in real life? blocks that can be used to build a What are the different types of decision-making capability in your code. operators? In the earlier chapters, we discussed How to combine multiple operators? how to handle decisions in a flow chart. Apply logical operations in block Now we shall see how to implement it in coding our code. We can do things conditionally in our programs using if statements or if/else 4.2 Arranging blocks statements combined with logical operators. Logical operators work like Boolean variables and return either In the image below, we see several blocks TRUE or FALSE. arranged in a specific order. Every time we place a new block, we apply logic to The three most important logical build a diagonal line with blocks marked operators are AND, OR and NOT. with arrows. This logic in coding terms are called conditions. Logical operators AND OR NOT 4.3 And operator 37 | P a g e AND operator is used to determine if two Yes No No or more conditions are true. If all the No No No conditions are true, the AND operator returns TRUE. If any one of the Having this example in mind, let us now conditions fail, the AND operator returns see how this is different from OR FALSE. In some programming languages operator. AND operator is denoted by “&&” symbol. 4.4 OR Operator For example - you should go to bed only after you have completed your homework and the time is past 8 PM. The OR operator is used to determine if either one of two or more conditions is Here, if we want to derive the logical TRUE. If any of the condition is true, the operation from this scenario, we have OR operator returns TRUE. If all the the following conditions: conditions fail, the OR operator simply Condition 1: Have you completed returns FALSE. In some programming homework? languages OR operator is denoted by “||” symbol. Condition 2: Is the time past 8 PM? For example - We should carry an And the decision we are deriving is: umbrella when either it is sunny, or it is Decision: Should you go to bed? raining. Otherwise, we should not carry it. Like the previous example, if we want Based on this we can write the below to derive the logical operation from this pseudo code: scenario, we have the following conditions: IF (Homework completed) AND (Time is past 8 PM) Condition 1: Is it sunny outside? THEN Go to bed Condition 2: Is it raining outside? ELSE Do not go to bed And the decision we are deriving is: END Decision: Should we carry an umbrella? The pseudocode for this will look like Let us now try to see the different below: combinations possible with the above pseudo code. IF (It is sunny outside) OR (It is raining outside) Condition 1 Condition 2 Decision THEN Have you Is the time Should Carry an umbrella completed past 8 PM? you go to ELSE homework? bed? Do not carry an umbrella END Yes Yes Yes No Yes No 38 | P a g e Shown below are the different possible combinations for the above example. Condition 1 Condition 2 Decision 4.6 Combining logical Is sunny? Is raining? Carry operators umbrella? Yes Yes Yes Yes No Yes Sometimes, we need to combine different No Yes Yes logical operators to create a complex No No No expression. Imagine your library is open on Monday between 10 AM to 12 PM OR on Wednesday between 3 PM to 5 PM. Let us now look at the NOT operator. IF (Day == Monday AND (Time >= 10 AM AND Time = 3 PM AND Time 0: print 'Current variable is:', a The break statement modifies the a = a -1 normal flow of execution while it if a == 5: terminates the existing loop and break continues execution of the statement following that loop. Break statement is print "Bye!" required as sometimes you want to break out of a loop early when a This is the result for the code condition is met. Let us now understand Break Statement Current variable is: 9 Current variable is: 8 with help of below pseudocode: Current variable is: 7 Current variable is: 6 Bye! As we see the control skips the lines after the break statement and executes the first statement outside the loop. 62 | P a g e 5.9 Continue Statement Example – Use continue statement to print number from 9 to 0 and does not print when the value is 5 Whenever a program comes across a continue statement, the control skips The pseudo code for this will look like the execution of remaining statements below: inside the loop for the current iteration and jumps to the beginning of the loop b=9 for the next iteration. If the loop's while b > 0: condition is still true, it enters the loop b = b -1 again, else the control will be moved to if b == 5: the statement immediately after the continue loop. This is somewhat similar to break print 'Current variable is:', a print statement and is used when we want to "Bye!" force the next iteration and skip some lines of code within the loop. Let us now understand continue This is the result for the code statements with the below pseudocode: Current variable is: 9 Current variable is: 8 Current variable is: 7 Current variable is: 6 Current variable is: 4 Current variable is: 3 Current variable is: 2 Current variable is: 1 Current variable is: 0 Bye! Now that we know the concepts of loops let us do an activity. 5.10 Activity: A tale of two As you can see, as soon as the continue villages statement is encountered, the lines below the continue statement are In this exercise, we will use basic coding skipped. But unlike the break concepts to bring two villages together in statement, the loop is not terminated. Minecraft: Education Edition. You Instead, the control jumps to the setup Minecraft education edition from beginning of the loop. https://education.minecraft.net/get- started 63 | P a g e 64 | P a g e 65 | P a g e 66 | P a g e There are many other challenges that can be done. Let us do one more to help villagers learn how to farm. 67 | P a g e Refer https://education.minecraft.net/hour-of-code-2020 for the entire activity. 5.11 Quiz time Objective Type Questions Question 1 The if statement is used to execute some code if a statement is true. Option 1 True Option 2 False Question 2 An else statement should always be after an if statement which executes when the code is false. Option 1 True Option 2 False 68 | P a g e Question 3 A while loop statement repeatedly executes a statement as long as the condition remains true Option 1 True Option 2 False Question 4 Without a statement that eventually evaluates the while loop condition to false, the loop will continue indefinitely Option 1 True Option 2 False Question 5 A for loop executes for a specific number of times Option 1 True Option 2 False Question 6 A continue statement is used to skip all the remaining statements in the loop and moves the control back to the top of the loop. Option 1 True Option 2 False Question 7 When a break statement is encountered inside a loop, the loop is immediately terminated, and the program execution moves on to the next statement in the loop. Option 1 True Option 2 False Question 8 Doing something over and over again or repeating code is called as Option 1 Code Option 2 loop Option 3 Program Option 4 Bug Question 9 Which is the correct operator for equality testing? Option 1 == Option 2 = Option 3 != 69 | P a g e Option 4 += Question 10 What is the output of the below pseudocode? Option 1 5 Option 2 10 Option 3 15 Option 4 0 count = 0; sum = 0; while (count < 5) { sum = sum + count; count = count + 1; } print sum; Question 11 Which letter won’t print while running the below pseudocode? Option 1 ‘d’ Option 2 ‘c’ Option 3 ‘n’ Option 4 ‘o’ for letter in "coding": if letter == "i": break print(letter) print("End") 70 | P a g e Question 12 Which letter won’t print while running the below pseudocode? Option 1 ‘g’ Option 2 ‘o’ Option 3 ‘d’ Option 4 ‘i’ for letter in "coding": if letter == "i": continue print(letter) print("End") Short Answer Questions 1. Define loops and nested loops in programming 2. What is an exit criterion? 3. How do we increment loops? 4. What is a break statement? 5. What is a continue statement? Higher Order Thinking Skills (HOTS) Now that you know the concept of Nested Loops. Using Arcade MakeCode platform create an example for nested loops. Applied Project Write a program using loops that ask the user to enter an even number. If the number entered does not display an appropriate message and asks them to enter a number again. Do not stop until an even number is entered. Print a congratulatory message at end. 71 | P a g e 5.12 What did you learn in this chapter? You should now have an idea of what are loops and how they are used in programming? Incrementing loops Different types of loops What is entry and exit criteria in loops and its usage? Break and continue statements Concept of nested loops 72 | P a g e REFERENCES Microsoft. 2021. Microsoft MakeCode Arcade. [Online]. [25 February 2021]. Available from: https://arcade.makecode.com Microsoft. 2021. Microsoft MakeCode for Minecraft. [Online]. [25 February 2021]. Available from: https://minecraft.makecode.com Microsoft. 2021. Computer Science Subject Kit | Minecraft: Education Edition. [Online]. [25 February 2021]. Available from: https://education.minecraft.net/class-resources/computer-science-subject-kit Microsoft. 2020. Activity: We Built a Zoo. [Online]. [25 February 2021]. Available from: https://education.minecraft.net/class-resources/computer-science-subject- kit ACM, Inc. 2021. Code of Ethics. [Online]. [25 February 2021]. Available from: https://www.acm.org/code-of-ethics Microsoft. 2020. Hour Of Code 2020 | Minecraft: Education Edition. [Online]. [25 February 2021]. Available from: https://education.minecraft.net/hour-of-code- 2020 73 | P a g e