0% found this document useful (0 votes)
73 views8 pages

Class 8 Answer Key

The document covers iterative statements in Python, including types of loops such as for and while, and their syntax. It also discusses the use of break statements, the purpose of conditional statements within loops, and provides exercises related to these concepts. Additionally, it includes sections on sequences, lists, and HTML elements such as lists and tables.

Uploaded by

adyansh4430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views8 pages

Class 8 Answer Key

The document covers iterative statements in Python, including types of loops such as for and while, and their syntax. It also discusses the use of break statements, the purpose of conditional statements within loops, and provides exercises related to these concepts. Additionally, it includes sections on sequences, lists, and HTML elements such as lists and tables.

Uploaded by

adyansh4430
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ITERATIVE

Chapter 3

STATEMENTS IN PYTHON
EXERCISE ZONE

A. Tick () the correct answer.


1. An iterative statement is also known as ____________ statement.
a) conditional b) looping c) selection
2. Which loop is used when you know the actual times the loop is to be repeated?
a) while b) for c) if.else
3. The break statement is used ____________ loops.
a) at beginning of b) inside c) outside
4. The ____________ operator checks whether a given value lies within a given set of
values.
a) between b) range c) for

B. Fill in the blanks.


1. Repetition of a statement again and again is called as iteration/ looping.
2. A step value is automatically incremented by one value if not specified.
3. The infinite loop never ends.
4. The while loop is used to repeat a block of statements until there is no item in any
sequence.

C. Write True (T) or False (F).


1. Ctrl + F is used to exit a loop. F
2. Each loop contains a variable known as the control variable. T
3. The ‘in’ is used as a membership operator in a for loop. F
4. There is only one iterative statement. F

D. Short answer type questions.


1. Define looping and name the types of loops used in Python, along with their syntax.
A: Looping is the process of repeating a block of code multiple times. Python has for and
while loops.

7
Syntax:
for<variable> in range (start, stop, step):
#Statements to be executed

Initialisation
while <condition>:
Loop body
Step value

2. What is the purpose of the break statement in loops?


A: The break statement is used to exit a loop immediately when a certain condition is met.

E. Long answer type questions.


1. Which function is used to define a range in a loop? Explain with an example.
A: The range () function is used to define a sequence of numbers in a loop.
Example:
for i in range (1, 6):
print(i) #prints numbers 1 to 5.
2. What is the purpose of using conditional statements within a loop?
A: Conditional statements within a loop help in making decisions and executing specific
code based on conditions, such as stopping a loop early or skipping certain iterations.

F. Application-based questions. (Critical and Logical Thinking)


1. Your friend is writing a program that seems to be running indefinitely. Which control
statement can he/ she use to exit the loop unconditionally when the desired number
is found?
A: The break statement can be used to exit the loop unconditionally.
2. While working on a Python program, you accidentally created an infinite loop. How
can you stop the execution of the program?
A: Press Ctrl + C or manually stop the program in the IDLE.

BACK IN ACTION
A. Lab activity.
1. What output will the following programs give?

8
3

2. Rewrite the following code after correcting the syntax error.


1 a=a+1 # Increment a is used before initialization.
while a<=10: # condition
print(a)
a=1 # Initialization
2num = 10 The condition in while (num >= 5) is missing
while (num >= 5) a colon: at the end, causing a syntax error.
print(num)
num = num - 1
3 a=5 A is incorrectly used instead of a (Python is
while a!= 0: case-sensitive).
print (“Run this code”)
a=A-1

4 for x range (5): Missing keyword in for loop


print(x)

5 for x in range (15,151,15): Incorrect indentation of the print(x)


print(x)

3. Complete the code of the following program.


1. Complete the following program to
calculate the sum of numbers until the
user enters 0.

2. Complete the following program that


takes two numbers from the user as
input and checks whether the first
number is divisible by the second
number. Display an appropriate
message based on the result.
9
SEQUENCES
Chapter 4

IN PYTHON

EXERCISE ZONE
A. Tick () the correct answer.
1. What type of data can a Python tuple store?
a) Only integers b) A sequence of immutable Python objects
c) Only strings
2. Which of the following is a mutable data type in Python?
a) String b) List c) Tuple
3. Which data type in Python is used to store a sequence of characters?
a) String b) Integer c) Boolean
4. Which of the following is a sequence data type in Python?
a) list b) float c) dictionary

B. Fill in the blanks.


1. A for loop is used to iterate over sequence data types like lists, tuples, and strings in
Python.
2. The break jump statement skips the current iteration and proceeds to the next one in a
loop.
3. The len () function returns the length of a sequence.
4. Lists, tuples, and strings are examples of sequence data types in Python.

C. Write True (T) or False (F).


1. A for loop can be used to iterate over any sequence data type in Python. T
2. Lists, tuples, and strings are examples of sequence data types in Python. T
3. The range () function in Python generates a sequence of floating-point numbers. F
4. The continue statement in a for loop stops the entire loop execution immediately. F

D. Short answer type questions.


1. What is a mutable and immutable sequence?
A: A mutable sequence allows modifications like adding, removing, or changing elements
after it is created (e.g., lists).
An immutable sequence cannot be changed after creation (e.g., tuples, strings).

10
2. What is negative indexing? Explain with an example.
A: Negative indexing in Python allows accessing elements from the end of a sequence.
Example:
my_list = [10, 20, 30, 40]
print (my_list [-1])
# Output: 40

E. Long answer type questions.


1. What is the difference between a list and a tuple?
A: A list is mutable, meaning elements can be changed, added, or removed. Example: [1,
2, 3]
A tuple is immutable, meaning its elements cannot be changed after creation. Example:
(1, 2, 3)
2. Explain the for loop with an example.
A: A for loop is used to iterate over a sequence like a list or string.
Example:
for num in [1, 2, 3]:
print(num)
# Output: 1 2 3

F. Application-based questions. (Critical and Logical Thinking)


1. In a Python program where you need to process each character in a string to check
for vowels, which loop structure would you use to iterate over the string, and what
type of sequence data is the loop applied to?
A: A for loop is used to iterate over a string, which is a sequence of characters, to check
for vowels.

BACK IN ACTION

A. Lab activity.
Complete the following code.
1. Calculate the factorial of a number.

11
2. Calculate the sum of numbers from 1 to 50.

12
LISTS, TABLES, &
Chapter 5

IMAGES IN HTML
EXERCISE ZONE

A. Tick () the correct answer.


1. Which tag is used for an unordered list?
a) <ul> b) <list> c) <unordered>
2. Which attribute of an image is used when the image is not displayed?
a) src b) alt c) alter
3. An unordered list is also known as __________ list.
a) numbered b) defined c) bulleted
4. __________ property helps in specifying the placement of a table caption.
a) caption-style b) caption-side c) caption-place

B. Fill in the blanks.


1. A definition list is used to define the terms in it.
2. The reversed attribute of the <OL> tag puts the list in descending order.
3. A list within another list is called a nested list.
4. The <tr> tag defines rows in a table.

C. Write True (T) or False (F).


1. The src attribute specifies the URL of the image. T
2. The default numbering in an ordered list is A, B, C, D, and so on. F
3. The List-style-type property specifies the type of list item marked that will be
used as a bullet. T
4. The tag <DT> is used to define the terms in a definition list. T

D. Short answer type questions.


1. What are different categories of lists that you can create using HTML5?
A: HTML5 allows creating three types of lists: Ordered List (<ol>), Unordered List (<ul>),
and Definition List (<dl>).

13
2. Which tag is used to insert images into a web page? State the significance of the
attributes alt and src in it.
A: The <img> tag is used to insert images into a web page. The src attribute specifies the
image URL, and the alt attribute provides alternative text for accessibility.

E. Long answer type questions.


1. What are tables? How can they be created in HTML5?
A: Tables in HTML5 are used to display data in rows and columns. They are created using
the <table> tag with <tr> for rows and <td> for cells. The <th> tag is used for
headers.
2. What is the difference between padding and border-spacing?
A: Padding is the space inside a cell between the content and the border, while border-
spacing is the space between adjacent table cells.

F. Match the following.


1. list-style-type a) Specifies pictures/images for markers
2. <dd> b) Specifies the placement of a table caption
3. list-style-image c) Description definition
4. caption-side d) Specifies different list item markers

G. Application-based questions. (Critical and Logical Thinking)


1. Rohan wants to specify the distance between the borders of the adjacent cells.
Which property should he use?
A: Rohan should use the border-spacing property to set the distance between the borders
of adjacent cells.

You might also like