Introduction To Coding - Cbse

Transcription

INTRODUCTIONTO CODINGGRADE VIStudent HandbookVersion 1.0

INTRODUCTIONTO CODINGGRADE VIStudent Handbook

ACKNOWLEDGEMENTPatrons Sh. Ramesh Pokhriyal 'Nishank', Minister of Human Resource Development,Government of IndiaSh. Dhotre Sanjay Shamrao, Minister of State for Human ResourceDevelopment, Government of IndiaMs. Anita Karwal, IAS, Secretary, Department of School Education and Literacy,Ministry Human Resource Development, Government of India AdvisoryEditorial and Creative Inputs Mr. Manuj Ahuja, IAS, Chairperson, Central Board of Secondary EducationGuidance and Support Dr. Biswajit Saha, Director (Skill Education & Training), Central Board ofSecondary EducationDr. Joseph Emmanuel, Director (Academics), Central Board of SecondaryEducationSh. Navtez Bal, Executive Director, Public Sector, Microsoft Corporation IndiaPvt. Ltd.Sh. Omjiwan Gupta, Director Education, Microsoft Corporation India Pvt. LtdDr. Vinnie Jauhari, Director Education Advocacy, Microsoft Corporation IndiaPvt. Ltd.Ms. Navdeep Kaur Kular, Education Program Manager, Allegis Services IndiaValue adder, Curator and Co-Ordinator Sh. Ravinder Pal Singh, Joint Secretary, Department of Skill Education, CentralBoard of Secondary Education

ABOUT THE HANDBOOKCoding is a creative activity that students from any discipline can engage in. It helps tobuild computational thinking, develop problem solving skills, improve critical thinkingand 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 classesVI-VIII from the Session 2021-2022 onwards. The idea is also to simplify the codinglearning experience by nurturing design thinking, logical flow of ideas and apply thisacross the disciplines. The foundations laid in the early years will help the students tobuild the competencies in the area of AI, data sciences and other disciplines.CBSE acknowledges the initiative by Microsoft India in developing this coding handbookfor class VI students. This handbook introduces concepts of coding and computationalthinking using real life examples and block coding with open source MakeCode platform.It uses gamified learning approach to make learning experience more engaging. Thebook is intuitive with practical examples of theoretical concepts and applied exercises.There are mini projects that students can work on. Additionally, the handbook alsofocuses on creating exposure to ethics of coding and promotes empathy among studentsby activities curated to demonstrate empathy and sensitivity.The purpose of the book is to enable the future workforce to acquire coding skills earlyin their educational phase and build a solid foundation to be industry ready.

RESOURCES FOR STUDENTSMinecraft education editionMinecraft education edition is a game-based learning platform that promotes creativity,collaboration, and problem-solving in an immersive digital environment. This platformprovides a fun way of learning coding and design thinking concepts. Visithttps://education.minecraft.net/ for more details.MakeCodeMicrosoft MakeCode is a free, open source platform for creating engaging computerscience learning experiences that support a progression path into real-worldprogramming. It brings programming to life for all students with fun projects, immediateresults, and includes both block and text editors for learners at different levels. Visithttps://www.microsoft.com/en-us/makecode for more details.GitHubGitHub is a storehouse where you can manage and collaborate on your code. It helps tomaintain different versions of the code easily. GitHub Student Developer Pack givesstudents free access to the best developer, web development, gaming and many othertools at no cost enabling practical learning.Sign up for the GitHub Student developer pack herehttps://education.github.com/discount requests/student application?utm source 2021-06-11-cbse

TABLE OF CONTENTSTable of Contents . IEthical practices in coding .1Introduction to Coding .21.1What will you learn in this chapter? .21.2How do traffic lights work?.21.3Where else do we see applications of coding?.21.4What exactly is coding? .21.5What is a programming language?.31.6Quiz Time .41.7What did you learn in this chapter? .5Algorithms With Block Coding .62.1What will you learn in this chapter? .62.2Searching for a word in the dictionary.62.3Flowcharts .72.3.1What is a Flowchart?.72.3.2Symbols used in a flowchart .72.3.3Benefits of using a flowchart.82.4Activity: Profit and loss with flowcharts .82.5Pseudocode.82.5.1What is a Pseudocode? .82.6Activity: Profit and loss with pseudocode .92.7Getting started with block coding .92.8Quiz time. 132.9What did you learn in this chapter? . 18Variables using block coding . 193.1What will you learn in this chapter? . 193.2What are variables? . 19I

3.3Naming variables . 193.4Data types in variables. 203.5Performing Operations on Variables. 233.6Activity: Addition operation using block coding . 243.7Quiz time. 343.8What did you learn in this chapter? . 36Control with conditionals. 374.1What will you learn in this chapter? . 374.2Arranging blocks. 374.3And operator . 374.4OR Operator. 384.5NOT Operator. 394.6Combining logical operators . 394.7Quiz time. 404.8Relational operators. 404.9Activity: Are you a teen? . 404.10Activity: Dynamic backgrounds. 414.11Nested Conditional Statements . 464.12Activity: The remainder problem. 464.13Quiz time . 504.14What did you learn in this chapter? . 53Loops using block coding. 545.1What will you learn in this chapter? . 545.2Introduction to loops . 545.3Increment Loops . 545.4Different types of loops. 555.5Activity: Building a music player . 585.6Entry Criteria . 615.7Exit Criteria . 615.8Break Statement . 625.9Continue Statement. 635.10Activity: A tale of two villages. 63II

5.11Quiz time . 685.12What did you learn in this chapter? . 72References . 73III

ETHICAL PRACTICES IN CODINGAs you build capabilities around coding, you will be equipped to build software on yourown, which will have an impact on society in general. So, it is very important to adhereto ethical practices while building your own code. Below are some practices you mustremember 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 privacyDo consider the aftereffects of the software. Ensure your Code respects diversityand is utilized responsibly with social issues in mindIn addition to this, promote environmental sustainability both locally and globallyAvoid harm to others Your code should not cause physical or mental injury, unjustified destruction toproperty or informationAvoid unjustified damage to reputation and environment1 Page

INTRODUCTION TO CODING1.1 What will you learn in thischapter?traffic signals to show different colors.Sometimes it is even smarter, where thecode detects congestion based onsensors and maximizes efficiency byonly functioning when traffic is present.Do you want to know what code is? Howis code applied in real life, and how doesit impact our day-to-day activities?Welcome to the introductory section oncoding.1.3 Where else do we seeapplications of coding?Here you will learn: Real world application of codingHow coding impacts our daily livesWhat exactly is coding in contextof computer scienceMost of us knowingly or unknowinglyengage with programming, be it insideour homes or outside. Coding, in themodern world, can be seen on thestreets, at the schools, at the localgrocery stores, etc.Some of the practical examples of codingin the real world are:1.2 How do traffic lights work?Have you ever wonderedhowtrafficsignalsfunction? The lights cyclethrough green, yellow,andredatregularintervals to control roadintersections' traffic flow. They preventaccidents and help to avoid congestionon the roads.However, how do the traffic lightschange automatically?Few lines of code running in thebackground drive the traffic lights. Atregular intervals, the code changes the2 Page Interaction with bar-codescanners at shopping storeAutomatic control of traffic usingtraffic lightsBooking movie, bus, train, flighttickets onlinePrintersComputer software we use likeweb browser, Word etc.Video games and animations forentertainment1.4 What exactly is coding?Coding,alsoreferredtoasprogramming, is creating instructionsthat can be executed on a computer to

perform a specific task or achieve aparticular result.Coding is just like solving a mathproblem. There may be many ways tosolve a problem. Similarly, there couldbe more than one way to writecode for the same task. Just like solvingany other problem, some codingapproaches are more efficient thanothers.Think you are playing a video on yoursmartphone. Your phone is like acomputer that needs to be instructed onwhat to be done. The app playing thevideo provides this instruction. Thisvideo-playing app is an example ofcoding. But how does the appcommunicate the instructions to thephone? It does via a programminglanguage. In the next section, we will getto know more about programminglanguages.1.5 What is a programminglanguage?Think about how we communicate withpeople around us? Language is ourprimary means of communication for allhuman interactions. Similarly, we caninteract with computers via a languagethat computers understand. Thislanguage is called a programminglanguage.Usingprogramminglanguages, we can provide instructionsto a computer to perform a set ofactivities. These sets of instructions arealso called programs. Like any otherlanguagethathasgrammar,programming languages have syntax.3 PageSome of the most frequently usedones are: PythonJavaJavaScriptC#RC CF#COBOLSyntax is a set of rules that we need tofollow when we write a computerprogram.There are hundreds of programminglanguages used around the world. Andnew ones are getting developed all thetime. Every programming language hasits own syntax. But all programminglanguages have one common thing: theyare eventually converted into a languagethat the computer will understand.

Throughout this chapter, we will learnabout different programming techniquesand how to apply them. Now, that weknow a little bit about coding and itsapplications, let us try to do someexercises.1.6 Quiz TimeQuestion 1For a given problem, there is always only one way to write a programOption 1Option 2TrueFalseQuestion 2Pin authentication for ATM card transaction is an example ofprogrammingOption 1Option 2TrueFalseQuestion 3Option 1Option 2Code is a set of instructions that can be executed on a computer toperform a specific taskTrueFalseQuestion 4Which among the below are examples of programming in real life?Option 1Option 2Option 3Option 4RobotsComputer GamesSelf-drive carsAll the aboveQuestion 5Which among the below is not an example of programming language?Option 1Option 2Option 3PythonEnglishJavaScript4 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 shouldunderstand How coding is being utilized in everyday life to perform complex tasks in an easymannerWhat 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 languages5 Page

ALGORITHMS WITH BLOCK CODINGhow does he find that word 'proxy' in the2.1 What will you learn in thischapter?Now that we already have a fairunderstanding of coding applications inreal life, let us understand how to solvea coding problem in detail. By the end ofthis chapter, you will learn: What does the term algorithmmean?What is a flowchart?Applications of flowchartGet introduced to pseudocode2.2 Searching for a word in thedictionaryWhile reading a book in a school library,Mukesh comes across a word say 'proxy'whose meaning he does not know. Sohow does he find out the meaning of thisword?The simple answer to this is thatMukesh searches for the meaning of theword 'proxy' in a dictionary. However,there are many words in a dictionary. So6 Pagedictionary?To achieve this, he first needs to find thedictionary section with the first letter ofthe word, which in this case is 'p.' Then,within the list of words starting the firstletter 'p', he needs to find the sectionhaving the second letter of the word 'r'.He needs to do this operation again withthe third, fourth & fifth letters until hefinally reaches the word 'proxy' in thedictionary & then finds its meaning.In other words, Mukesh needs to followa set of steps to complete the task offinding the meaning of a word.Similarly, before writing a program codefor a given problem in computer science,

it is essential to devise a set of steps tobe followed to solve the problemsuccessfully. This set of steps is calledan algorithm.Thus, in computer science, an algorithmis defined as the step-by-step plan tosolve the problem for a given problemstatement.2.3 Flowcharts2.3.1 What is a Flowchart?Aflowchart isadiagrammaticrepresentation of the step-by-step planto be followed for solving a task/problemstatement.This diagrammatic representation ismade up of shapes like boxes,diamonds,parallelograms,circles,ellipses connected by arrows. Eachshape acts as a step in the solution, andthe arrows represent the direction offlow among the steps.2.3.2 Symbols used in a flowchart7 Page

2.3.3 Benefits of using a flowchart The focus is mainly on including allSome of the benefits of using a flowchartare:1. It helps to explain your approachtowards solving a problem2. The flowchart helps in bringing invisual clarity to a problem, so ithelps in practical problem solving3. Once you build a flowchart, thisremains as documentation of thecode you are about to build. If youneedtocome backandunderstand the code, you canrefer to the flowchart.2.4 Activity: Profit and losswith flowchartsShown in the image is a flowchart thattakes two inputs, namely cost price andselling price. It then calculates profit orloss depending on the values and printsthe same. 2.5 Pseudocode2.5.1 What is a Pseudocode?In computer science, pseudocode isused to describe the steps followed in analgorithmviasimplehumancomprehensible language. Thus, it hasno syntax of any programming languageand can be understood by a layman. Theadvantages of representing the solutionas pseudocode are multifold:8 Page the essential steps to solve theproblem. Thus, the solution tends tobe comprehensiveReviewers can quickly review thepseudocode & verify if the steps willgenerate the desired outcomeWhile writing pseudocode, you canfocus on all possible scenarios. So,this helps you understand thepotential problems that might comeup laterSince you are not worried aboutcoding syntax, you can concentrateon the actual problemWriting pseudocode will help writingyour code much easierWorks as documentation of the code.So even a layman with no codingknowledge canrefertothepseudocode

2.6 Activity: Profit and losswith pseudocodeNow that we have a fair understandingof flowcharts and pseudocode, let us tryto implement the same profit and lossproblem using pseudocode.Program startsRead Cost Price (CP)Read Selling Price (SP)If (SP CP) thenProfit SP – CPPrint ProfitElseLoss CP – SPPrint LossProgram ends2.7 Getting started with blockcodingMicrosoft MakeCode is a framework forcreating interactiveand engagingprogramming experiences for those newto the world of programming.The main objective of MakeCode is tobring programming to the forefront in away that is more alluring and friendly.To achieve this, MakeCode utilizes theblocks programming model to let thosewho are new to the world of9 Pageprogramming and learn coding conceptseasily.MakeCode Arcade is one of the platformsto perform block-based programming.Using arcade, solution to a problemstatement can be implemented usingvarious categories of blocks and theresults can be seen side by side on thesame screen.The different categories of blocks will beexplored in the upcoming chapters.Note: Minecraft is just one of theplatforms for block coding. You can usemany similar platforms available onlinefor block coding like – /code.org/) etc.We will now start a simple block codingexercise on Minecraft platform.Open the URLhttps://arcade.makecode.com in yourfavorite web browser.

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 timeObjective type questions1. Select a word from column A and place it in a cell on column B such that itsdefinition matches in cells of column CABCAlgorithmWriting steps involved tosolve a problem in atformcodingPseudo CodeDefine step by step plantosolvea problemstatementArcadeSolution to a problempresented as a diagramBelow is a flowchart to calculate profit and loss. Answer questions 2 to 4 based on theflowchart.13 P a g e

Question 2Option 1Option 2Question 3Option 1Option 2Question 4Option 1Option 214 P a g eJyoti owns a toy shop. She bought a toy for Rs 325 and sold it for Rs.375. Which one from the below is correct?She made a loss of Rs. 50She made a profit of Rs. 50Raju buys a pen for Rs 15, and after some time, he sells it for Rs 10.Which one from the below is correct?He made a loss of Rs. 5He made a profit of Rs. 5Ram buys a table for Rs 500, he sells it for Rs 550. Which one fromthe below is correct?He made a loss of Rs. 50He made a profit of Rs. 50

Question 5Which of the following is not an advantage of a flowchart?Option 1Option 2Option 3Option 4Efficient codingSystematic testingImproper documentationBetter communicationQuestion 6The following box denotes.Option 1Option 2Option 3Option 4InitializationDecisionInput / OutputConnectorsQuestion 7What is a flowchart?Option 1Option 2Option 3Option 4AAAAQuestion 8What shape represents the start and end of a flowchart?Option 1Option 2Option 3Option 4SquareDiamondOvalCirclespecific programming languagetext-based way of designing an algorithmbullet point list of instructionsdiagram that represents a set of instructionsShort Answer questions1. 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 thecorresponding 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 threesubjects are greater than 75. If average marks are less than or equal to 75, thenit prints "Below average marks". Draw the corresponding flowchart for theproblem.16 P a g e

Program startsRead marks for subject SubARead marks for subject SubBRead marks for subject SubCCalculate AverageMarks (SubA SubB SubC)/3Print AverageMarksIf (AverageMarks 75)Print (“Above Average Marks”)ElsePrint (“Below Average Marks”)Program endsApplied ProjectCreate a flowchart based on your normal school day. Here are some guidelines:Getting ready for school Look at your timetable and pack your school bagIf PE is there packing your PE uniform and shoesAt school Attend the morning session with subjects Math, English and scienceA decision on what to play during recessAfter reaching home Have snacksDepending on the day, choose the class you have to attend.Monday-Karate, Tuesday-Math Class, Wednesday and Thursday Free day,Friday-Karate17 P a g e

2.9 What did you learn in this chapter? By now you should have a basic understanding about algorithms, flowchart& pseudocodeYou have also practiced following a step by step approach to solve a problemusing block-based programmingYou got oriented to MakeCode platform which we will use throughout thecourse18 P a g e

VARIABLES USING BLOCK CODING3.1 What will you learn in thischapter?program. Any defined variable cannot beaccessed beyond its scope.3.3 Naming variables What are variables?How to name variables?Commonly used data typesPerforming operations on variables3.2 What are variables?In programming, variable is a packet inwhich we can store data. These packetscan be named and referenced and can beused to perform various operations. Toperform a mathematical operation, youcan declare two variables and performthe operation on them.Scope of a variable refers to the part ofthe code where the variable can be used.The scope or accessibility of thevariables defined in a program dependson where you have declared it in each19 P a g eAs we have understood till now,variables are basically like nouns in aprogramming language. Every variablein a program is unique. To identify thesevariables uniquely, user needs toallocate them a unique name. This nameacts as an identifier for that variable. Inprogramming, a user is not allowed touse the same name of a variable morethan once.Naming variables make it to easier to callthem while performing operations. Thename of a variable also suggests whatinformation the variable contains.You can refer to the example before forbetter understanding about variables:If variable named as "a" is equal to 2 andvariable named as "b" is equal to 2,

performing add operation on "a" and "b"is going to result into an output as "4".3.4 Data types in variablesVariables are the values that are actedupon. Every value needs to be assignedto a specific data type to make thevariable more readable by a computer.Data type identifies what the type of datathat the declared variable can hold is.Thus, it indirectly helps the computer tounderstand what operations need to beperformed on those variables. Thedeclaration of a variable in a programcontains two components – the name ofthe variable and its type.Let us now understand what are thecommon data types that we can use inprogramming: IntegerFloating-point numberCharacterStringBooleaninteger variable and assign it a noninteger value, the program returns anerror.Variables of the integer data type areonly capable of holding single values.These variables are not capable ofholding a long list of values.Floating Point Number Data TypeFloating-point numbers are used tostore decimal values. They hold minglanguage, the syntax to declare floatingpoint variable changes.Example of declaring a floating-pointnumber variable:float a 1.1;There is another type of floating-pointnumber known as a "double" data type,which is used to store even biggervalues.Integer Data TypeInteger data type variables store integervalues only. They store whole numberswhich have zero, positive and negativevalues but not decimal values. Multipleprogramminglanguagessupportdifferent syntax to declare an Integervariable. If a user tries to create anExample of declaringvariable:int a 2;20 P a g ean IntegerExample of a double value:double a 8.999999999 *7.66666666666;Character Data TypeCharacter type variables are used tostore character values. Syntax ofdeclaring a character variable is specificto the programming language that you

are using. If a user tries to create acharacter variable and assign it with anon-character value, the program willthrow an error. The character data typeisthesmallestdata typeinprogramming.Any character values can be declared asa char variable.data types for variables as per programneeds andassign variablesanappropriate data type.Boolean is a subtype of integer datatype. It stores true and false where truemeans non-zero and false means zero.Example ofvariable:String Data TypeTo extend the character data type, a usermay have a requirement to store andperform an operation on a sequence ofcharacters. In such cases, the Stringdata type is present to fit the gap. TheString data type stores value in asequence of characters i.e. in Stringformat.declaringaStringString a “I am a String Variable”;Note: In some programming languageslike python, there is no command toExample of declaring variables inpythona 5b “Hello”declare variables. A variable is createdthe moment you first assign a value to it.If you want to specify the data type ofvariable this can be done using casting.Example: y str(7)Any string value can be declared as astring variable.z int(7)a float(7)y will be saved as ‘7’Boolean Data TypeThere is a subtype of Integer Data Typecalled "Boolean Data Type", which storesvalues in Boolean type only i.e. "true" or"false". Users can choose between the21 P a g eBooleanAny Boolean variable holding Booleanvalue can be declared as Boolean.char a ‘w’;ofabool a true;Example of declaring a charactervariable:Examplevariable:declaringz will be saved as 7a will be saved as 7.0

Let us now apply different data types ina pseudocode. We will first declareInteger i 1234567890Function -------------------Float f 1.234Declare Integer iChar c cDeclare Float fString s stringDeclare Char cBoolean b trueDeclare String sdifferent types of variables, followed byassigning them to appropriate values.Finally, we will use the variables byoutputting their values.Declare Boolean ---------Assign i 1234567890Assign f 1.234Assign c ‘c’Assign s "string"Assign b ----------Output "Integer i " & iOutput "Float f " & fOutput "Char c " & cOutput "String s " & sOutput "Boolean b " & bEndThe output from the above pseudocodewill be like below.Note: The syntax is different for differentdata types in other programminglanguages.22 P a g e

In python string variab

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