Page 1 :
5.Elements of Coding, Exercises, 1.Tick the correct answer., a. Cycling is an example of a loop., b. English language cannot be used to give specific instruction to a computer., c. Dummy code used by programmers is called pseudocode., d. Snakes and ladder is a game that uses the concept called conditional statement., e. Python is an example of a high -level language., 2. Fill in the blanks., a. The informal way of writing a code or an algorithm is known as pseudocode, b. Carrying an umbrella because it is raining is an example of conditional statement, c. Computer code= Logic + Syntax, d. Finite loop repeat till a specified condition is met., e. Performing an action based on a given condition is the concept behind conditional statements., 3. Match the following, a. Multiplication (v) i) Bug, b. Errors in a code (i) ii) Algorithm, c. Steps to solve a problem (ii) iii) syntax, d. Programming languages (iii) iv) Conditional statement, e. If age>60, print’senior citizen (iv) v) repeated addition, 4. Answer the following questions., a. What are loops? Explain with examples., Ans-An action which repeats till until a specified condition is met is called a loop. Loops are applicable not only to moving objects, but to any phenomenon that repeats., Example-Day and Night: This is an endless loop, b. Discuss the two types of loops., Ans-Loops are broadly of two types:, Finite Loops: Loops that finish after a specified number of repetitions., Infinite Loops: Such loops keep repeating till they are stopped., c. What are the conditional statement? Describe with the help of two examples from your daily life., Ans-Performing an action based on a given condition is the concept behind conditional statements., In everyday life, there are many actions that we perform based on certain conditions. Some examples are as follows: If we are thirsty, we drink water. If it is raining, we carry an umbrella or wear a raincoat. If the traffic light is red, we stop the vehicle., d. What is a pseudocode?, Ans-The informal way of writing the code before its final implementation is known as the pseudocode., e. What is the difference between algorithm and pseudocode?, Ans-An algorithm is used to provide a solution to a particular problem in form of well-defined steps. Whenever you use a computer to solve a particular problem, the steps which lead to the solution should be properly communicated to the computer., Pseudocode is one of the methods which can be used to represent an algorithm for a program. It does not have a specific syntax like any of the programming languages and thus cannot be executed on a computer., 5. Write the pseudocode., a. Subtract two numbers, Pseudocode, Start, Input the two numbers: x, y, Subtract x and y, and store in answer, (iv) Display answer, (v) Stop, b. Check if a number is divisible by 2, Pseudocode, Start, ii) DISPLAY “Enter the Number - “, READ n, IF n MOD 2 = 0 THEN, DISPLAY "Number is divisible by 2”, ELSE, DISPLAY "Number is not divisible by 2”, END IF, (v) STOP, c. Take the temperature from the user as input. Depending on the temperature, print ‘Cold’, ‘Hot’ or ‘Room temperature’., Pseudocode, Start, DISPLAY “Enter the temperature in Fahrenheit - “, READ temp, IF temp = 70 0 THEN, DISPLAY "Room temperature”, ENDIF, IF temp < 70 THEN, DISPLAY "Cold”, ENDIF, IF temp > 70 THEN, DISPLAY "Hot”, ENDIF, (vii) STOP