Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Standard Question

1. What are the different types of control structures? Define each type.

Control structures: Control structures are used in programming to control the flow of
execution. They determine how different parts of a program are executed based on certain
conditions. Here are three common types of control structures:
a. Sequence: It represents a set of instructions executed in a specific order, one after
another.
b. Selection: It allows the program to make decisions and choose between different paths
based on certain conditions. Common selection structures include if statements and switch
statements.
c. Iteration (or loop): It enables the program to repeat a certain block of code multiple times
until a specific condition is met. Common iteration structures include for loops, while loops,
and do-while loops.

2. What are the different types of relational operators?

Relational operators: Relational operators are used to compare values and determine the
relationship between them. Here are the common relational operators:
a. Equal to (==): Checks if two values are equal.
b. Not equal to (!=): Checks if two values are not equal.
c. Greater than (>): Checks if the value on the left is greater than the value on the right.
d. Less than (<): Checks if the value on the left is less than the value on the right.
e. Greater than or equal to (>=): Checks if the value on the left is greater than or equal to the
value on the right.
f. Less than or equal to (<=): Checks if the value on the left is less than or equal to the value on
the right.

3. What are logical operators? Name different types of logical operators.

Logical operators: Logical operators are used to combine or modify logical conditions in
programming. They work with Boolean values (true or false). Here are the common logical
operators:
a. AND (&&): Returns true if both conditions on either side of the operator are true.
b. OR (||): Returns true if at least one of the conditions on either side of the operator is true.
c. NOT (!): Negates the logical value of a condition. If a condition is true, applying the NOT
operator makes it false, and vice versa.

4. What are the differences between "AND" and "OR" operators? Give examples.

Differences between "AND" and "OR" operators:


The "AND" operator (&&) returns true only if both conditions on either side of the operator
are true. It can be visualized as a gate that is open only when both conditions are met. For
example:
if (x > 5 && x < 10):
# Executes when x is greater than 5 and less than 10
The "OR" operator (||) returns true if at least one of the conditions on either side of the
operator is true. It can be visualized as a gate that is open if either condition is met. For
example:
if (x == 0 || x == 10):
# Executes when x is equal to 0 or 10
5. What is a nested conditional statement and where is it used?
Nested conditional statement: A nested conditional statement is a conditional statement (if
statement) that is placed inside another conditional statement. It allows for more complex
decision-making by considering multiple conditions. Nested conditionals are used when
certain conditions need to be checked only if another condition is true. Here's an example:
if (x > 0):
if (y > 0):
print("Both x and y are positive")
else:
print("x is positive but y is not")
else:
print("x is not positive")
In the above example, the second if statement is nested inside the first if statement. It
checks whether both x and y are positive only if x is positive. If x is not positive, the nested if
statement is skipped and the corresponding message is printed.
Higher Order Thinking Skills
Q1. 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 und 9.
Program to check if a number is divisible by 7 or 9 or both:
# Assign a number to the variable
number = 63

# Check if the number is divisible by 7 or 9


if number % 7 == 0 and number % 9 == 0:
print("The number is divisible by both 7 and 9")
elif number % 7 == 0:
print("The number is divisible by 7")
elif number % 9 == 0:
print("The number is divisible by 9")
else:
print("The number is not divisible by 7 or 9")

Q2. Create a program in Minecraft which assigns a number to a variable. Then display if the number
is even or odd.
Program to check if a number is even or odd:
# Assign a number to the variable
number = 12

# Check if the number is even or odd


if number % 2 == 0:
print("The number is even")
else:
print("The number is odd")

Q3. 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.
Program to check if a number is divisible by 3 and multiply it by 10 if true: # Assign a
number to the variable
number = 27

# Check if the number is divisible by 3


if number % 3 == 0:
# Multiply the number by 10
number *= 10
print("The number is divisible by 3. Result: " + str(number))
else:
print("The number is not divisible by 3")

You might also like