TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 1.
What are types of alternative or branching statements python provides?
Answer:
There are three types of alternative or branching statements python provides.
They are : –

  1. Simple if statement
  2. if.. .else statement
  3. If.. .elif statement.

Question 2.
Write a note on pass statement.
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.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 3.
What is nested loop structure?
Answer:

  1. A loop placed within another loop is called as nested loop structure.
  2. One can place a while within another while, for within another for.
  3. For within while and while within for to construct such nested loops.

Question 4.
What is range ()?
Answer:

  1. In python, for loop uses the range ( ) function.
  2. The range ( ) function in the sequence to specify the initial, final and increment values.
  3. range () can also take values from string, list, dictionary etc.,
    Eg: range(1, 30, 2)

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 5.
What is out put?
Answer:
i = 25
while (i< = 30):
print (i, end =’\t’)
i = i+1
Output: 25 26 27 28 29 30

Question 6.
Write the output of the following segment for word in ‘SCHOOL:
Answer:
print (word, end =”)
Output: SCHOOL

Question 7.
What are keywords to achieve jump statements in python?
Answer:
There are three keywords to achieve jump statements in python, break, continue, pass.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 8.
What is output? for i in “My school”:
Answer:
if i ==”h”:
break
print (i, end=”)
Output: My sc

Question 9.
What are the parameters used print statement in python?
Answer:

  1. Print statement can have end and sep as parameters.
  2. End parameter can be used when we need to give any escape sequences like ‘it’ for tab, ‘in’ for new line and so on.
  3. step parameter can be used to specify any special characters like , (comma), (;) semicolon as parameter between values.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 10.
What is jump statement? What are the types of statement?
Answer:

(i) In python, the jump statement is used to unconditionally transfer the control from one part of the program to another.
(ii) There are three keywords to achieve jump statement is python. They are break, continue and pass.
(a) The break statement terminates the loop containing it.
(b) The continue statement is used to skip the remaining part of a loop.
(c) The pass statement in python programming is a null statement.

Question 11.
Write a python to replace punctuation with whitespace.
Answer:

TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures 1

for i in s :
if i not in punc_list: new_s t?=i
return new s. lower()

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 12.
Write a python program to calculate 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 13.
What is output?
for i in “SCHOOL”
if i ==’C’:
continue
print (i)
Answer:
The output is S.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 14.
Write a python program use for within while loop.
Answer:
i = 1
while (i<=6):
for j in range (1, i):
print (j, end=’\t’)
print (end = ‘\n’) i+=1
output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 15.
List the control structures in Python.
Answer:
There are three important control structures, they are

  • Sequential
  • Alternative or Branching
  • Iterative or Looping.

Question 16.
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. If the break statement is inside a nested loop, break will terminate the innermost loop.

Question 17.
Write is the syntax of if. else statement.
Answer:
The if…else statements provides control to check the true block as well as the false block.
The syntax of if..else statement is
if < condition> :
statements-block 1
else
statements-block 2

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 18.
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.

Question 19.
Write note on range ( ) in loop.
Answer:
range ( ) can also take values from string, list dictionary etc, Usually in python, for loop uses the range() function in the sequence to specify the initial, final and increment values. range ( ) generates a list of values starting from start till stop-1.

Question 20.
Write a program to display A
A B
A B C
A B C D
A B C D E
# Program to display Alphabet pattern
Answer:
for i in range (1, 6):
for j in range (65, 65+i):
a = chr (j)
print (a, end= ” “)
print ( )

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 21.
Write note on if..else structure.
The if…else statement provides control to check the true block as well as the false block.
The syntax is
Answer:
if <condition>:
Statement-block 1 else:
Statement-block 2
The condition if is cheeked, if it is true, statement-block 1 is executed, otherwise statement-block 2 is executed.
If-else statement thus provides two possibilities and the condition determines which block is to be executed.
Eg:
# example pgm for if….else
structure
a= int (input (“Type the number”))
if a%2 ==0:
print (a, “is an even number”)
else:
print (a, “is an odd number”)

Question 22.
Using if..else..elif statement write a suitable program to display largest of 3 numbers.
Answer:
# Python program to display largest of three numbers using if..else., elif statement.
a = float (input (“Type first value”))
b = float (input (“Type second value”))
c = float (input (“Type Third value”))
if (a>b and a>c):
print (“{0} is greater than both {1} and {2}”. format (a, b, c))
elif (b>a and b>c):
print (“{0} is greater than both {1} and {2}”. format (b, a, c))
elif (c>a and c>b):
Print (“{0} is greater than both {1} and {2}”. format (c, a, b))
else:
Print (“Either any two values or all the three values are equal”).

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 23.
Write the syntax of while loop.
Answer:
The syntax of while loop is
while <condition>:
statement block 1
else:

statement block 2:

Hence the while loop, the condition is any valid Boolean expression returning true or false. The else part of while is optional.
The statement 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.

Question 24.
List the differences between break and continue statements.
Answer:

Break  Continue
The break statement terminates the loop containing it.  Continue statement unlike the break statement is used to skip the remaining skip the remaining part of a loop and start with next iteration.
A while or for loop will iterate till the condition is tested false, but one can even transfer the control out of the loop with the help of break statement.  The working of continue statement in for and while loop start the next iteration.
If break statement is inside a nested loop, break will terminate the innermost loop.  The use of continue statement inside the loop, after the continue statement will be executed.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 25.
Write a detail note on for loop.
Answer:
For loop is entry check loop and most comfortable loop.
The condition is checked in the beginning and the body of the loop is executed if it is only true otherwise the loop is not executed.
The syntax is
for counter-variable in sequence:
statement – block 1
else
statement – block 2

But usually python, for loop uses the range ( ) function in the sequence to specify the initial, final and increment values.
range ( ) function generates a list of values starting from start till stop-1
The syntax of range () is range (start, stop, [step])
Where
Start- refers to the initial value
Stop- refers to the final value
Step- refers to the increment value, this is optional part.
Eg:
range (1, 30, 1), when this statement is executed will start the range of values from 1 and end at 29.
range (2, 30, 2), when this statement is executed will start the range of values from 2 and end at 28.
Example for segment as for i in range (2,10, 2):
print (i, end=ll)
The output will be printed as 2 4 6 8.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 26.
Write a detail note on if..else..elif statement with suitable example.
Answer:
if…else statement:
The if…else statement provides control to check the true block as well as the false block.
The syntax is
if <condition>:
Statement-block 1
else
Statement-block 2

If….else statement thus provides two possibilities and the condition determines which block is to be executed.
Eg:
# example program to check odd or even
a = int (input (“Type the number”))
if a%2 = = 0:
print (a, “is an even number”)
else:
print (a, “is an odd number”)
elif statement 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.
Eg:
m1 = int (input (“Type the first mark”))
m2 = int (input (“Type the second mark”))
avg = (m1+m2)/2
if Avg> =80
print (“Grade A”)
elif avg>=70 and avg< 80
print (“Grade B”)

Question 27.
Write a program to display all 3 digit odd numbers.
Answer:
# To display all 3 digit odd numbers.
L = int (input (“Type the 3 digit starting number”))
U = int (input (“Type the 3 digit ending number”))
For i in range (L, U+l):
If (i %2 !=0):
print (i)

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 28.
Write a program to display multiplication table for a given number.
Answer:
# Program to display multiplication table
t= int (input (“Type the table number”))
n= int (input (“Type the steps”))
print (“multiplication Table of’, t)
for i in range (1, b):
print (t, “X”, i, “=”, t*i)

Hands On Experience (TB. P.No. 86):

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

Question 2.
Using if..else..elif statement check smallest of three numbers.
Answer:
# Program for check smallest of three numbers.
n1, n2, n3 = map (int, input (“Enter the three numbers”).split (“ ”))
if (n1<n2 and n1< n3):
print (“{ } is smallest, format (nl))
elif (n2< n3):
print (“{ } is smallest, format (n2))
else:
Print (“{ } is smallest, format (n3))

Question 3.
Write a program to check if a number is Positive, Negative or zero.
Answer:
# Program to check if a number is positive, negative or zero.
n = float (input (“Type a number”))
if n > 0:
Print (“Positive number”)
elif n==0:
print (“zero”)
else
print (“ Negative number”)

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 4.
Write a program to display Fibonacci series 0 1 12 3 4 5 (upto n terms).
Answer:
# Program to display Fibonacci series
nterms = int (input (“Type How many terms”)
n1 = 0
n2 = 1
count =0
if nterms < =0:
Print (“please type the positive number”)
elif nterms==1:
print (“Fibonacci sequence upto n terms”)
print (n1)
while count < nterms:
print (n1, end =‘,’)
nth = n1+n2
n1=n2
n2=nth
count+=1

Question 5.
Write a program to display sum of natural numbers, upto n.
Answer:
# program to display sum of natural numbers,
n = int (input (“Type the n number”))
s=0
while (n>0):
s +=n
n-= 1
print (“ The sum is”, s)

Question 6.
Write a program to check if the given number is a palindrome or not.
Answer:
# program for given number is a palindrome or not
n = int (input (“Type the number”))
temp = n
rev = 0
while (n>0):
dig=n% 10
rev = rev* 10 + dig
n=n//10
if (tern == rev):
print (“The number is a palindrome”)
else:
print (“The number is not a palindromes”)

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 7.
Write a program to print the following pattern
* * * * *
* * * *
* * *
* *
*
Answer:
# program to print the half pyramid pattern,
r = input (“Type number of rows”)
r = int (r)
for i in range (r, o, -1):
for j in range (o., i+1):
print (“*”, end=‘ ’)
print (‘\r’)

Question 8.
Write a program to check if the year is leap year or not.
Answer:
# program to check if the year is leap years or not
y= int (input (“Type, year to be checked”))
if (y%4 ~0 and y% 100 ! = 0 or y%400 =0):
print (“The year is a leap year”)
else:
print (“The year is not a leap year”).

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Choose the best answer:

Question 1.
Which statement allows to execute group of statements multiple times?
(a) loop
(b) continue
(c) print
(d) input
Answer:
(a) loop

Question 2.
Which statement is an entry check loop in python?
(a) while
(b) for
(c) do…while
(d) if…elif
Answer:
(a) while

Question 3.
Which statement is a null statement in python?
(a) break
(b) contime
(c) pass
(d) end
Answer:
(c) pass

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 4.
Match the following:

(i) for  (A) branching statement
(ii) while  (B) null statement
(iii) if… else  (C) looping statement
(iv) pass  (D) entry check loop

(a) (i) – C, (ii) – D, (iii) – A, (iv) – B
(b) (i) – C, (ii) – A, (iii) – B, (iv) – D
(c) (i) – B, (ii) – C, (iii) – A, (iv) – D
(d) (i) – B, (ii) – D, (iii) – A, (iv) – C
Answer:
(a) (i) – C, (ii) – D, (iii) – A, (iv) – B

Question 5.
Choose the incorrect pair:
(a) program – set of statements
(b) loop – multiple times
(c) continue – jump statement
(d) pass – skipped statement
Answer:
(d) pass – skipped statement

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 6.
Choose the incorrect statement:
(a) A sequential statement is composed statements.
(b) Simple if is the all decision making statements.
(c) A loop allows to execute the statement one by one.
(d) For loop is the most comfortable loop.
Answer:
(c) A loop allows to execute the statement one by one.

Question 7.
Pick the odd one out:
(a) for
(b) while
(c) pass
(d) if…else
Answer:
(c) pass

Question 8.
Assertion (A):
A sequential statement is composed of a sequence of statement which are executed one after another.
Reason (R):
A code to print your name, address and phone number is an example of sequential statement.
(a) Both A and R are true, And R is the correct explanation for A.
(b) Both A and R are true, But R is not the correct explanation for A
(c) A is true but R is false.
(d) Both A and R are false.
Answer:
(a) Both A and R are true, And R is the correct explanation for A.

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 9.
Choose the correct pair:
(a) Branching – Alternative
(b) Sequencing – Jumping
(c) Iteration – Sequencing
(d) Indentation – Nested
Answer:
(a) Branching – Alternative

Question 10.
Choose the correct statement.
(a) Pass statement in python programming is a control statement.
(b) Pass statement when executed by the interpreter it is completely ignored.
(c) Pass statement is generally used as a stop the execution.
(d) Pass statement can be used at the top of the program.
Answer:
(b) Pass statement when executed by the interpreter it is completely ignored.

Question 11.
Which of the following is not a type of branching statement?
(a) while
(b) if
(c) if-else
(d) if-elif
Answer:
(a) while

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 12.
for i in range (0, 10, 2), print (I). The output is:
(a) 1, 3, 5, 7, 9
(b) 0, 2, 4, 6, 8
(c) 2, 4, 6, 8, 10
(d) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Answer:
(b) 0, 2, 4, 6, 8

Question 13.
Which of the following is not a nested loop?
(a) Jump
(b) while
(b) for within if
(d) pass
Answer:
(d) pass

Question 14.
Which statement is used to skip the remaining part of a loop and start with next iteration?
(a) continue
(b) break
(c) pass
(d) goto
Answer:
(a) continue

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 15.
The program statements which are executed one after another is called:
(a) Sequential
(b) Looping
(c) Branching
(d) Iterative
Answer:
(a) Sequential

Question 16.
The program statements executed for multiple times are called:
(a) Sequential
(b) Looping
(c) Branching
(d) Iterative
Answer:
(b) Looping

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 17.
Which of the following optional part of while statement?
(a) if
(b) elif
(c) else
(d) if-else
Answer:
(c) else

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

Question 19.
elif can be considered to be abbreviation of
(a) nested if
(b) if.else
(c) else if
(d) if..elif
Answer:
(c) else if

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

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

Question 21.
Which statement is generally used as a placeholder?
(a) continue
(b) break
(c) pass
(d) goto
Answer:
(c) pass

Question 22.
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 TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 23.
Which is the most comfortable loop?
(a) do..while
(b) while
(c) for
(d) if..elif
Answer:
(c) for

Question 24.
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

Question 25.
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:
(b) True

Samacheer Kalvi TN State Board 12th Computer Science Important Questions Chapter 6 Control Structures

Question 26.
Which amongst this is not a jump statement ?
(a) for
(b) goto
(c) continue
(d) break
Answer:
(a) for

Question 27.
Which punctuation should be used in the blank?
if <condition>_
statements-block 1,
else:
statements-block 2
(a) ;
(b) :
(c) ::
(d) !
Answer:
(b) :

TN Board 12th Computer Science Important Questions