CBSE Class 11 - Python Conditional Statements - Computer Science/ Informatics Practices

Q1: What do conditional statements do?

Answer: Conditional statements let us write program to do different tasks or take different paths based on the outcome of the conditions.

Q2: What is meant by a control structure?

Answer: A control structure is a logical design that controls the order in which a set of statements execute.

Thre are three types of control structures:

1. Sequence or sequential: The statement execute him top to bottom sequentially

2. Conditional or selection: Selection used for decisions, branching . choosing between two or more alterative paths.

3. Repetition or loop or itantive Repetition used for looping, i.e. repeating a piece of code multiple times in a row.

Q3: What are the three ways to write if...else statements?

if statement — executes the statement(s) inside if when the condition is true.

e.g.

if age >= 18:

print("Eligible to vote.")

if...else statement executes the statement(s) inside if when the condition is true, otherwise executes the statement(s) inside else (when the condition is false)

num1 = 10

num2 = 20

if num2 > num1:

print(num2, "is greater")

else:

print(num1, "is greater")

if...elif....else is use dot check multiple conditions and execute statements accordingly. Meaning of elif is elseif. We can also write elseif instead of elif for more clarity.

number = int(input("Enter a number: "))

if number > 0:

print("Number is positive")

elif number < 0:

print("Number is negative")

else:

print("Number is zero")

Q4: What is the meaning of the following boolean expressions using relational operators?

x> y

x< y

x >= y

x <= y

x == y

x != y

x> y : Is x greater than y?

x< y : Is x less than y?

x >= y : Is x greater than or equal to y?

x <= y : Is x less than or equal to y?

x == y : Is x equal to y?

x != y : Is x not equal to y?

Q5(MCQ): A __________ structure can execute a set of statements only under certain circumstances.

(a) sequence

(b) circumstantial

(c) decision

(d) Boolean

Q6: See the following python snippet:

a = 33

b = 200

if b > a:

print("b is greater than a")

What type of error is thrown by the print statement?

Q7: What is the output of the following Python snippet?

a = 33

b = 33

if b > a:

print("b is greater than a")

elif a == b:

print("a and b are equal")

else:

print("a is greater than b")

Answer: a and b are equal

Q8: What is the output of the following snippet?

a = 2

b = 330

print("A") if a > b else print("B")

Q9(MCQ): and, or, and not are __________ operators.

(a) relational

(b) logical

(c) conditional

(d) ternary

Q10: What is the meaning of the following expression?

x > y and a < b

Answer: Is x greater than y AND is a less than b?

Q11: What is the output of the following python snippet?

if (4 + 5 == 10):

print ("TRUE")

else:

print (FALSE")

print ('TRUE)

FALSE

TRUE

Q12: Write a python program to enter 3 number and print the largest number

n1 = int(input("Enter first number "))

n2 = int(input("Enter second number "))

n3 = int(input("Enter third number "))

large = n1

if (large<n2):

large=n2

if(large<n3):

large=n3

print("Largest number is ", large)

Q13: Write a program to check if entered year is leap year or not.

year = int(input("Enter any year "))

if year % 100 == 0:

if year % 400 == 0:

print("Year is Leap Year ")

else:

print("Year is not Leap Year")

elif year %4 ==0:

print("Year is Leap Year ")

else:

print("Year is not Leap Year")

Q14: Write a program to check if number is odd or even.

i = int(input("Enter a natural number? "))

if i % 2 == 0:

print("Number is even")

else:

print("Number is odd")  