Chapter : 8 Statements in Python
A.
Tick the correct answers.
1. What are iterative statements in Python?
a. Commands that make a part of the program be executed
repeatedly.
b. Commands that define conditions in a program
c.
Commands
that allow user to give input
Answer:
a. Commands that make a part of the program be executed repeatedly.
2. look at the following code:
age= int(input("How old are you?"))
if (age>=21):
print("Adult")
else:
print("Teenager")
What will be printed on the screen if the value of age is
21?
a. Adult b. Teenager c. Nothing will
print
Answer:
a. Adult
3. Which for statement will you use to print the
multiplication table of 17?
a. for i in range (1,10,17)
b. for i in range (10,1,17)
c.
for i
in range (17, 171,17)
Answer:
c. for i in range (17, 171,17)
n = int(input("Enter the
number "))
for i in range(17,171,17):
c = n*i
print(n,"*",i,"=",c)
output
Enter the number 17
17 * 17 = 289
17 * 34 = 578
17 * 51 = 867
17 * 68 = 1156
17 * 85 = 1445
17 * 102 = 1734
17 * 119 = 2023
17 * 136 = 2312
17 * 153 = 2601
17 * 170 = 2890
Process finished with exit code 0
4. The starting value of ‘i’ is 1 and it gets incremented
by 1. Which of the following while conditions will you use to repeat a task ten
times?
a. While (i<10) b. while (i<11) c. while (i!=10)
Answer: c. while (i!=10)
5. Which of these looping conditions will induce an
infinite loop? The starting value of I is 0.
a. While (i>0) b. for I in range (1, I, 1) c. while (i==0)
Answer : c.
while (i==0)
B.
Fill in the blanks.
1. The three types of control statements are sequential,
conditional,
and iterative.
2. Statements that allow you to give conditions are
called conditional
statements.
3. The if…elif…else statement
is used to check multiple conditions.
4. The while loop
is the simplest of all looping structures.
5. Infinite loops will only stop when there is a user- defined
break applied to it.
C.
Write T for true or F for False.
1. There is a clone(:) after the if condition. Answer :- T
2. For is a conditional statement. Answer:- F
3. The if...elif statement can be seen as an if within an
if statement. Answer:- T
4. A list contains ordered but interchangeable items. Answer:- T
5. You cannot use else statements in while loop. Answer:- F
D. Answer
the following questions.
1.
What are control structures?
Answer: According to the
structure theorem, any computer program can be written using the basic control
structures. A control structure (or flow of control) is a block of
programming that analyses variables and chooses a direction in which to go
based on given parameters. In simple sentence, a control structure is just a
decision that the computer makes. So, it is the basic decision-making
process in programming and flow of control determines how a computer
program will respond when given certain conditions and parameters.
2.
What are the three types of control structures used in Python?
Answer: There
are three basic types of control structures:
i.
Sequential Statements,
ii.
Selection or Conditional Statements and
iii.
Iterative or Repetition Statements.
3.
Differentiate between a list and a tuple.
Answer:
List vs. Tuple
SN |
List |
Tuple |
1 |
The literal syntax of list is shown by the []. |
The literal syntax of the tuple is shown by the
(). |
2 |
The List is mutable. |
The tuple is immutable. |
3 |
The List has the a variable length. |
The tuple has the fixed length. |
4 |
The list provides more functionality than a
tuple. |
The tuple provides less functionality than the
list. |
5 |
The list is used in the scenario in which we need
to store the simple collections with no constraints where the value of the
items can be changed. |
The tuple is used in the cases where we need to
store the read-only collections i.e., the value of the items cannot be changed.
It can be used as the key inside the dictionary. |
6 |
The lists are less memory efficient than a tuple. |
The tuples are more memory efficient because of
its immutability. |
4.
What is the use of range() function in for loop?
Answer: The range() function
The range() function is used to
generate the sequence of the numbers. If we pass the range(10), it will
generate the numbers from 0 to 9. The syntax of the range() function is given
below.
Syntax:
range(start,stop,step size)
o
The start represents the beginning of the
iteration.
o
The stop represents that the loop will iterate till
stop-1. The range(1,5) will generate numbers 1 to 4
iterations. It is optional.
o
The step size is used to skip the specific numbers
from the iteration. It is optional to use. By default, the step size is 1. It
is optional.
5.
What are infinite loops?
Answer: Infinite loops are loops that continues forever, and
never ends. Loops are those which may last forever, until a given condition is
meet. The only way to come out of such a loop is to apply a condition-specific
break.
0 Comments
If you have any doubts, Please let me know.