CBSE Coding Class 8 Solution – Conditionals in Details
CBSE Coding Class 8 Solution Student Handbook Chapter 1 Conditionals in Details all Questions and Answers Solution by Coding Teacher. Net Ex. Here provided all Coding Solution for Class 8.
(1) Which one of the following options is not a logical operator?
Answer: WHAT
Reason: Because OR, AND, NOT are logical operators.
(2) Which of the following can create conditional statements?
Answer: All the above
Reason: If, If -Else and nested If-Else all can create conditional statement.
(3) Which operator negates a condition?
Answer: NOT
Reason: We use NOT operator to negate a condition.
Standard Questions
(1) What are different types of control structures? Define each type.
Answer: Control structures control the flow of execution in a program, Control structures take decisions about program flow based on given parameters, it is a basic decision-making process in computing. It is like a prediction that program makes by accessing the given parameters.
There are three basic types of control structures in programming:
(1) Sequential
(2) Selection/Conditional
(3) Iteration
Sequential – In sequential control structure, the statements are run in a sequence of order from line 1 of the program to the end, i.e., step-by step in an order that they are written. Example of sequential Control system that we use in Day-to-day life is our morning routine.
Selection/Conditional – A selection (conditional) control structure is used to test a condition in a program. Selection control follows IF this THEN that logic. Selection control structure is fully based on the condition, if the condition is valid the code which satisfy the condition will execute otherwise the code which doesn’t satisfy the condition will be executed.
Iteration –Iteration control structure also known as Repetitive control structure is able to repeat some lines of code until the mentioned condition is not True. Loops are the examples of Iterative statements.
(2) What are the different types of relational operators?
Answer: The full list of relational operators
OPERATOR | SYMBOL | EXAMPLE | MEANING |
Greater than | > | x > y | X greater than y |
Equal to | == | x == y | X is equal to y |
Less than | > | x < y | x is less than y |
Greater than equal to | >= | x >= y | x is either greater than or equal to y |
Less than equal to | <= | x <= y | x is either less than or equal to y |
Not equal to | != | x != y | x not equal to y |
(3) What are logical operators? Name different types of logical operators.
Answer: Logical operators are fundamental blocks that can be used to build a decision-making capability in your code. When we need to make our decision based on two or more checks, it is necessary to have a combination of logical operators.
The three most important logical operators are AND, OR and NOT
AND Operator
The AND operator is used to combine two conditions. If all the conditions are true, the AND operator returns TRUE. If any one of the conditions fail, the AND operator returns FALSE. In python AND operator is denoted by and keyword. Some other programming languages use “&&” as AND operator.
For example:
Number = 10
If (number == 10 && number > 5 &&number != 6 ):
Print(“this is the example of AND operator”)
OR Operator
The OR operator returns True when one or more than one condition is True and it returns False when all the conditions are False. Here even if one condition true it will return True. In python syntax OR operator is denoted by or keyword. Some other programming languages use “||” as OR operator.
For example:
number = 20
If (number == 10 || number > 5 || number != 6 ):
Print(“this is the example of OR operator”)
NOT Operator
We use the NOT operator to reverse or negate a condition. If the condition is true, NOT will return false and if the condition is False, NOT will return True. We use not keyword to denote not operator. Some other programming languages use “!” as NOT operator.
For example: number = 15
If (! (number == 10)):
Print(“this is the example of NOT operator”)
(4) What are the differences between “AND” and “OR” operators? Give examples.
Answer: AND operator is used to see if two or more conditions are true. If all the conditions are true, the AND operator returns TRUE.
If any one of the conditions fail, the AND operator returns FALSE.
For example – you should go to bed only after you have completed your homework and the time is past 8 PM.
IF (Homework completed) AND (Time is past 8 PM)
THEN
Go to bed
ELSE
Do not go to bed END
END
While OR operator is used to see if either one of two or more conditions is TRUE. If any of the condition is true, the OR operator returns TRUE. If all the conditions fail, the OR operator simply returns FALSE.
For example – We should carry an umbrella when either it is sunny, or it is raining. Otherwise, we should not carry it.
IF (It is sunny outside) OR (It is raining outside)
THEN
Carry an umbrella
ELSE
Do not carry an umbrella END
END
(5) What is a nested conditional statement and where is it used?
Answer: A nested conditional statement is an if or if else statement inside another if else statement. for checking complex scenarios, we might find that using a single if-else loop is not enough. So, we can use a combination of if, else if statement inside another if block.
Example: To check if a number is divisible by 4 or 5 or both we can use a nested conditional statement, We can use if else condition inside an if else condition to check.
Program to check the number is divisible by 4 or 5 or both
number = 20
If number % 4 == 0:
If number % 5 == 0:
Print(“Number is divisible by 4 and 5 both”)
Else:
Print(“Number is divided by 4 only”)
Elif number % 5 == 0:
If number % 4 == 0:
Print(“Number is divisible by 5 and 4 both”)
Else:
Print(“Number is divided by 5 only”)
Else:
Print(“Number is neither divisible by 4 nor 5”)
Higher Order Thinking Skills (HOTS)
(1) Create a program in Minecraft which assigns a number to a variable. Then checks if the number is divisible by 7 or 9 or both 7 and 9.
Answer:
(2) Create a program in Minecraft which assigns a number to a variable. Then display if the number is even or odd.
Answer:
(3) Create a program in Minecraft which assigns a number to a variable. Find out if the number is divisible by 3. If divisible by 3, multiply it by 10 and display the output.
Answer:
Applied Project
Problem Statement: There are three children named Rohit, Priya and Pooja. Height of Rohit, Priya and Pooja are 4.8 ft 5.2 ft and 5.1 ft respectively. Create a program in Minecraft using block coding to find who is the tallest of three.
Solution:
Third hots is wrong
Third high order thinking skills is wrong it came wrong output for me in the mine craft please update this to the correct answer it will be very helpful.thank you.
Third hots is very wrong please
Correct it….