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?
Answer:
① 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
Answer:
ⅰ 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
Answer: (c) decision
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?
Answer: Indentation error
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")
Answer: B
Q9(MCQ): and, or, and not are __________ operators.
(a) relational
(b) logical
(c) conditional
(d) ternary
Answer: (b) logical
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)
Answer:
FALSE
TRUE
Q12: Write a python program to enter 3 number and print the largest number
Answer:
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.
Answer:
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.
Answer:
i = int(input("Enter a natural number? "))
if i % 2 == 0:
print("Number is even")
else:
print("Number is odd")
👉See Also:
CH1 - Computer OverviewComputer Systems Overview (MCQs)
Python Programming Basics (MCQs) - YouTube Video
Python Basics - Literals (Q & A)
Python Basics - Augmented Assignment Operators
Python Basics - String Manipulation (Part-1)
Python Basics - String Manipulation (Part-2)
No comments:
Post a Comment
We love to hear your thoughts about this post!
Note: only a member of this blog may post a comment.