Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Students can Download Computer Science Chapter 6 Control Structures Questions and Answers, Notes Pdf, Samacheer Kalvi 12th Computer Science Book Solutions Guide Pdf helps you to revise the complete Tamilnadu State Board New Syllabus and score more marks in your examinations.

Tamilnadu Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Samacheer Kalvi 12th Computer Science Control Structures Text Book Back Questions and Answers

PART – I
I. Choose The Best Answer

Question 1.
How many important control structures are there in Python?
(a) 3
(b) 4
(c) 5
(d) 6
Answer:
(a) 3

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
elif can be considered to be abbreviation of ……………………….
(a) Nested if
(b) If … else
(c) Else if
(d) If ……… Else
Answer:
(a) Nested if

Question 3.
What plays a vital role in Python programming?
(a) Statements
(b) Control
(c) Structure
(d) Indentation
Answer:
(d) Indentation

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Which statement is generally used as a placeholder?
(a) Continue
(b) Break
(c) Pass
(d) Goto
Answer:
(c) Pass

Question 5.
The condition in the if statement should be in the form of ……………………….
(a) Arithmetic or Relational expression
(b) Arithmetic or Logical expression
(c) Relational or Logical expression
(d) Arithmetic
Answer:
(c) Relational or Logical expression

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 6.
Which is the most comfortable loop?
(a) do..while
(b) While
(c) For
(d) if….elif
Answer:
(c) For

Question 7.
What is the output of the following snippet?
i = 1
while True:
if i % 3 = 0:
break
print(i, end = “)
i + = 1
(a) 12
(b) 123
(c) 1234
(d) 124
Answer:
(a) 12

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 8.
What is the output of the following snippet?
T = 1
while T: print(True)
break
(a) False
(b) True
(c) 0
(d) No output
Answer:
(d) No output

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 9.
Which amongst this is not a jump statement?
(a) For
(b) Goto
(c) Continue
(d) Break
Answer:
(a) For

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 10.
Which punctuation should be used in the blank?
if _
statements – block 1
else:
statements – block 2
else:
(a) ;
(b) :
(c) ::
(d) !
Answer:
(b) :

PART – II
II. Answer The Following Questions

Question 1.
List the control structures in Python?
Answer:
There are three important control structures

  1. Sequential
  2. Alternative or Branching
  3. Iterative or Looping

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Write note on break statement?
Answer:
The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.

Question 3.
Write is the syntax of if .. else statement?
Answer:
Syntax:
if:
statements – block 1
else:
statements – block 2

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Define control structure?
Answer:
A program statement that causes a jump of control from one part of the program to another is called control structure or control statement. As you have already learnt in C++, these control statements are compound statements used to alter the control flow of the process or program depending on the state of the process.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 5.
Write note on range 0 in loop?
Answer:
Usually in Python, for loop uses the rangeQ function in the sequence to specify the initial, final and increment values. rangeQ generates a list of values starting from start till stop – 1.

PART – III
III. Answer The Following Questions

Question 1.
Write a program to display?
A
A B
A B C
A B C D
A B C D E
Answer:
Program code: for i in range(1, 6):
for i in range(65, 65 + i)
a = chr (j)
print a
print

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Write note on ifi.else structure?
if .. else statement
Answer:
The if., else statement provides control to check the true block as well as the false block. Following is the syntax of ‘if.else’ statement.
Syntax:
if:
statements – block 1
else:
statements – block 2

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 3.
Using if..else..elif statement write a suitable program to display largest of 3 numbers. Display Largest of 3 Numbers?
Answer:
num 1 = int (input(“Enter first number : “))
num 2 = int (input(“Enter second number : “))
num 3 = int (input(“Enter third number : “))
if (num 1 > num 2) and (num 1 > num 3):
largest = num 1
elif (num 2 > num 1) and (num 2 > num 3):
largest = num 2
else:
largest = num3
print (“The largest number is”, largest)
Output:
Enter first number: 7
Enter second number: 5
Enter third number: 4
The largest number is 7

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Write the syntax of while loop?
Answer:
The syntax of while loop in Python has the following syntax:
Syntax:
while:
statements block 1
[else:
statements block 2]

Question 5.
List the differences between break and continue statements?
Answer:
Break statement:
Break statement has even skipped the ‘else’ part of the loop and has transferred the control to the next line following the loop block.

Continue statement:
Continue statement unlike the break statement is used to skip the remaining part of a loop and start with next iteration.

PART – IV
IV. Answer The Following Questions.

Question 1.
Write a detail note on for loop?
for loop:
for loop is the most comfortable loop. It is also an entry check loop. The condition is checked in the beginning and the body of the loop(statements – block 1) is executed if it is only True otherwise the loop is not executed.
Syntax:
for counter _ variable in sequence:
statements block 1
# optional block
[else:
statements block 2]
The counter_variable mentioned in the syntax is similar to the control variable that we used in the for loop of C++ and the sequence refers to the initial, final and increment value.

Usually in Python, for loop uses the rangeQ function in the sequence to specify the initial, final and increment values, ranged) generates a list of values starting from start till stop – 1.
The syntax of range O is as follows:
range (start, stop, [step])
Where,
start – refers to the initial value
stop – refers to the final value
step – refers to increment value, this is optional part.
Examples for range 0
range (1, 30, 1) will start the range of values from 1 and end at 29
range (2, 30, 2) will start the range of values from 2 and end at 28
range (30, 3, -3) will start the range of values from 30 and end at 6
range (20) will consider this value 20 as the end value(or upper limit) and starts the range count from 0 to 19 (remember always range 0 will work till stop – 1 value only).

# program to illustrate the use of for loop – to print single digit even number
fori in range (2, 10, 2):
print (i, end = ‘ ‘)
Output:
2 4 6 8

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Write a detail note on if..else..elif statement with suitable example?
Answer:
Nested if..elif…else statement:
When we need to construct a chain of if statement(s) then ‘elif’ clause can be used instead of ‘else’.
Syntax:
if:
statements – block 1
elif:
statements – block 2
else:
statements – block n

In the syntax of if..elif..else mentioned above, condition – 1 is tested if it is true then statements-block 1 is executed, otherwise the control checks condition – 2, if it is true statements-block2 is executed and even if it fails statements – block n mentioned in else part is executed.

‘elif’ clause combines if.else – if.else statements to one if.elif… else, ‘elif’ can be considered to be abbreviation of ‘else if’. In an ‘if’ statement there is no limit of ‘elif’ clause that can be used, but an ‘else ’clause if used should be placed at the end

m1 = int (input(“Enter mark in first subject: ”))
m2 = int (input(“Enter mark in second subject: ”))
avg = (m1 + m2)/2
if avg> = 80:
print (“Grade: A”)
elif avg> = 70 and avg<80: print (“Grade: B”) elif avg> = 60 and avg<70: print (“Grade: C”) elif avg> = 50 and avg<60:
print (“Grade: D”)
else:
print (“Grade: E”)

Output 1:
Enter mark in first subject: 34
Enter mark in second subject: 78
Grade: D

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 3.
Write a program to display all 3 digit odd numbers?
Answer:
Odd Number (3 digits)
for a in range (100, 1000)
if a % 2 = = 1:
print b
Output:
101, 103, 105, 107, .. …… 997, 999

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Write a program to display multiplication table for a given number?
Answer:
Multiplication table
num = int (input(“Enter the number : “))
print (“multiplication Table of “, num)
for i in range(1, 11):
print (num, “x”, i,”=”, num*i)
Output:
Enter the number: 6
Multiplication Table of 6
6 × 1 = 6
6 × 2 = 12
6 × 3 = 18
6 × 4 = 24
6 × 5 = 30
6 × 6 = 36
6 × 7 = 42
6 × 8 = 48
6 × 9 = 54
6 × 10 = 60

Practice Programs

Question 1.
Write a program to check whether the given character is a vowel or not?
Answer:
ch = input(“Enter a character : “)
if ch in (‘a’, ’A’, ‘e’, ‘E’, ‘i’, ‘I’, ‘o’, ‘O’, ‘u’, ‘U’):
print (ch,’is a vowel’)
else:
print (ch the letter is not a vowel’)
Output:
Enter a character: e
e is a vowel

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Using if..else..elif statement check smallest of three numbers?
Answer:
num 1 = int (input(“Enter first number : “))
num 2 = int (input(“Enter second number : “))
num 3 = int (input(“Enter third number : “))
if (num 1 < num 2) and (num 1 < num 3):
smallest = num 1
elif (num 2 < num 1) and (num 2 < num 3): smallest = num 2 else: smallest = num 3 print(” The smallest number is”, smallest) Output: Enter first number: 12 Enter second number: 7 Enter third number: 15 The smallest number is 7 Question 3. Write a program to check if a number is Positive, Negative or zero? Answer: num = int(input(“Enter a number : “)) if num > 0:
print (“positive number”)
elif num = = 0:
print(“zero”)
else:
print (“Negative number”)
Output:
Enter a number: 2
positive number

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Write a program to display Fibonacci series 01 1235 (up to n terms)?
Answer:
n terms = int (input (“How many terms?”))
n1 = 0
n2 = 1
count = 2
# check if the number of tenns is valid
if n terms <= 0:
print (“please enter a positive integer”)
elif n terms = =1:
print (“Fibonacci sequence:”)
print(n1)
else:
print (“Fibonacci sequence :”)
print (n1, n2, end = “,”)
while count < nterms: nth = n1 + n2 print(nth, end =’, ‘) n1 = n2 n2 = nth count + = 1 Output: How many terms? 10 Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

Question 5.
Write a program to display sum of natural numbers, upto n?
Answer:
n = input(“Enter any number”) sum = 0 for i in range(i, n + 1): sum = sum + i print “sum = “, sum
Output:
Enter any number 5
sum =15

Question 6.
Write a program to check if the given number is a palindrome or not?
Answer:
n = int(input(“Enter any Number : “)) temp = n rev = 0 while (n >0):
dig = n%10
rev = rev * 10 + dig
n = n // 10
if (temp = = rev):
print (“palindrome”)
else:
print (“not a palindrome”)
Output:
Enter any Number 2332
palindrome

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 7.
Write a program to print the following pattern?

Program:
for i in range(0, 5):
for j in range(5, i, -1):
print (“*”, end = “”)
print ( )

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 8.
Write a program to check if the year is leap year or not?
Answer:
n = int (input(“Enter any year”))
if (n % 4 = 0):
print “Leap Year”
else:
print “Not a Leap Year”
Output:
Enter any Year 2000
Leap Year

Samacheer kalvi 12th Computer Science Control Structures Additional Questions and Answers

PART – I
I. Choose The Best Answer

Question 1.
Executing a set of statements multiple times are called as …………………………..
(a) Iteration
(b) Looping
(c) Branching
(d) Both a and b
Answer:
(d) Both a and b

Question 2.
A program statement that causes a jump of control from one part of the program to another is called ………………………….
Answer:
Control Structure.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 3.
Identify which is not a control structure?
(a) Sequential
(b) Alternative
(c) Iterative
(d) Break
Answer:
(d) Break

Question 4.
A ………………………… is composed of a sequence of statements which are executed one after the another.
Answer:
Sequential Statement

Question 5.
Branching statements are otherwise called as ……………………………
(a) Alternative
(b) Iterative
(c) Loop
(d) Sequential
Answer:
(a) Alternative

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 6.
…………………………… is the simplest of all decision making statements.
Answer:
Simple If

Question 7.
…………………………….. statement provides control to check the true block as well as the false block.
Answer:
If ………. else

Question 8.
How many blocks can be given in Nested if.. elif.. else statements?
(a) 1
(b) 2
(c) 3
(d) n
Answer:
(d) n

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 9.
How many types of looping constructs are there?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(b) 2

Question 10.
The ………………….. part of while is optional.
Answer:
Else

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 11.
What types of Expressions can be given in the while loop?
(a) Arithmetic
(b) Logical
(c) Relational
(d) Boolean
Answer:
(d) Boolean

Question 12.
Which one of the following is the entry check loop type?
(a) While
(b) Do while
(c) If
(d) If…else
Answer:
(a) While

Question 13.
How many parameters are there in print function?
(a) 2
(b) 3
(c) 4
(d) 5
Answer:
(a) 2

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 14.
Escape sequences can be given using …………………………. parameter in print ( ) function.
(a) Ret
(b) Let
(c) End
(d) Sep
Answer:
(c) End

Question 15.
Which parameter is used to specify any special characters?
(a) Ret
(b) Let
(c) End
(d) Sep
Answer:
(d) Sep

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 16.
If the condition is checked in the beginning of the loop, then it is called as ……………………… loop.
(a) Exit
(b) Exit check
(c) Entry check
(d) Multiple
Answer:
(c) Entry check

Question 17.
range ( ) generates a list of values starting from start till ………………………..
Answer:
Stop – 1

Question 18.
Which is the optional part in range ( ) function?
(a) Start
(b) Stop
(c) Step
(d) Incr
Answer:
(c) Step

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 19.
The end value of range (30, 3, -3) is ………………………..
(a) 30
(b) -3
(c) 3
(d) 6
Answer:
(d) 6

Question 20.
range(20) has the range value from ……………………….. to ………………………..
Answer:
0 to 19

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 21.
range ( ) cannot take the values from ………………………..
(a) String
(b) Print
(c) List
(d) Dictionary
Answer:
(b) Print

Question 22.
A loop placed within another loop is called as ………………………..
Answer:
Nested loop

Question 23.
……………………….. statements are used to unconditionally transfer the control from one part of the program to another.
(a) While
(b) Jump
(c) For
(d) If
Answer:
(b) Jump

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 24.
How many keywords are there to achieve Jump statements in python?
(a) 1
(b) 2
(c) 3
(d) 4
Answer:
(c) 3

Question 25.
Pick the odd one out.
break, for, continue, pass.
Answer:
For

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 26.
………………………. is used to come out of loop.
(a) Break
(b) For
(c) Continue
(d) Pass
Answer:
(a) Break

Question 27.
If a loop is left by ……………………… then the else part is not executed.
Answer:
Break

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 28.
………………………….. statement forces the next iteration to takes place.
(a) Break
(b) For
(c) Continue
(d) Pass
Answer:
(c) Continue

Question 29.
……………………. is the null statement.
(a) Break
(b) For
(c) Continue
(d) Pass
Answer:
(d) Pass

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 30.
Python …………………….. will throw error for all indentation errors.
Answer:
Interpreter.

PART – II
II. Answer The Following Questions

Question 1.
Write note on sequential statements?
Answer:
A sequential statement is composed of a sequence of statements which are executed one after another. A code to print your name, address and phone number is an example of sequential statement.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Name the different types of alternative statements in Python?
Answer:
Python provides the following types of alternative or branching statements:
Simple if statement if……else statement if….elif statement

Question 3.
Define loops?
Answer:
Iteration or loop are used in situation when the user need to execute a block of code several of times or till the condition is satisfied. A loop statement allows to execute a statement or group of statements multiple times.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Give the diagram for while loop execution?
Answer:

Question 5.
Give the syntax of range O in for loop?
Answer:
The syntax of range ( ) is as follows:
range (start, stop, [step] )
Where,
start – refers to the initial value
stop – refers to the final value
step – refers to increment value, this is optional part.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 6.
Give the diagram for ‘for loop’ execution?
Answer:

Question 7.
Define nested loops?
Answer:
A loop placed within another loop is called as nested loop structure. One can place a while within another while; for within another for; for within while and while within for to construct such nested loops.

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 8.
Write note on Jump statements in python?
Answer:
The jump statement in Python, is used to unconditionally transfer the control from one part of the program to another. There are three keywords to achieve jump statements in Python : break, continue, pass.

PART – III
III. Answer The Following Questions

Question 1.
Give the syntax for simple if statements and if else
simple if
Syntax:
Answer:
if:
statements – block 1
if else
Syntax:
variable = variable 1 if condition else variable 2

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Give the flow chart diagram for if..else statement execution?
Answer:
if..else statement thus provides two possibilities and the condition determines which BLOCK is to be executed.

Question 3.
Write a python program to check whether the given number is odd or even?
Example: #Program to check if the accepted number odd or even
Answer:
a = int (input(“Enter any number:”))
if a%2 = = 0:
print (a, ” is an even number”)
else:
print (a,” is an odd number”)

Output 1:
Enter any number: 56
56 is an even number

Output 2:
Enter any number: 67
67 is an odd number

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 4.
Give the flowchart diagram for if..elif…else statement execution?
Answer:

Question 5.
Give a diagram to illustrate how looping construct get executed?
Answer:

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 6.
Explain the two parameters of print ( ) function?
Answer:
print can have end, sep as parameters, end parameter can be used when we need to give any escape sequences like ‘\t’ for tab, ‘\n’ for new line and so on. sep as parameter can be used to specify any special characters like, (comma); (semicolon) as separator between values.

Question 7.
Give the syntax for ‘for loop’?
Answer:
Syntax:
for counter_variable in sequence:
statements – block 1
[else: # optional block
statements – block 2]

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 8.
Write the program to calculate the sum of numbers from 1 to 100.
Example: # program to calculate the sum of numbers 1 to 100
Answer:
n = 100
sum = 0
for counter in range (1, n + 1):
sum = sum + counter
print (“Sum of 1 until %d: %d” % (n,sum))
Output:
Sum of 1 until 100: 5050

Question 9.
Draw the flowchart to illustrate the use of break and continue statements in loop?
Answer:

Question 10.
Give the syntax for break, continue and pass?
Answer:
Syntax:
break
Syntax:
continue
Syntax:
pass

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 11.
Write short note on pass statements?
Answer:
pass statement in Python programming is a null statement, pass statement when executed by the interpreter it is completely ignored. Nothing happens when pass is executed, it results in no operation. pass statement can be used in ‘if’ clause as well as within loop construct, when you do not want any statements or commands within that block to be executed.

PART – IV
IV. Answer The Following Questions

Question 1.
Explain If and If..else with sample programs?
Answer:
Simple if statement:
Simple if is the simplest of all decision making statements. Condition should be in the form of relational or logical expression.

Syntax:
if :
statements – block 1
In the above syntax if the condition is true statements – block 1 will be executed.

Example
# Program to check the age and print whether eligible for voting
x = int (input (“Enter your age :”))
if x > = 18:
print (“You are eligible for voting”)

Output 1:
Enter your age: 34 You are eligible for voting

Output 2:
Enter your age: 16
>>>
As you can see in the second execution no output will be printed, only the Python prompt will be displayed because the program does not check the alternative process when the condition is failed.

if..else statement:
The if., else statement provides control to check the true block as well as the false block. Following is the syntax of ‘if.else’ statement.

Syntax:
if:
statements – block 1
else:
statements – block 2

if..else statement thus provides two possibilities and the condition determines which BLOCK is to be executed.
Example: #Program to check if the accepted number odd or even
a = int(input(“Enter any number :”)) if a%2==0:
print (a,” is an even number”)
else:
print (a, ” is an odd number”)

Output 1:
Enter any number: 56 56 is an even number

Output 2:
Enter any number: 67 67 is an odd number
An alternate method to rewrite the above program is also available in Python. The complete if.else can also written as:

Syntax:
variable = variable 1 if condition else variable 2

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 2.
Explain while loop with sample program,
while loop
The syntax of while loop in Python has the following syntax:
Syntax:
while:
statements block 1

In the while loop, the condition is any valid Boolean expression returning True or False. The else part of while is optional part of while. The statements block 1 is kept executed till the condition is True. If the else part is written, it is executed when the condition is tested False.

Recall while loop belongs to entry check loop type, that is it is not executed even once if the condition is tested False in the beginning.
Example: program to illustrate the use of while loop – to print all numbers from 10 to 15
i = 10 # initializing part of the control variable
while (i< = 15): # test condition
print (i, end =’\t’) # statements – block 1
i = i + 1 # Updation of the control variable
Output:
10 11 12 13 14 15

Samacheer Kalvi 12th Computer Science Solutions Chapter 6 Control Structures

Question 3.
Write a python program to display the following output.?
Answer:

i = 1
while (i< = 6):
for j in range (1, i):
print (j, end = \t’)
print (end =’\n’)
i + = 1

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!