Chapter 8: Iterative Statements in Python
Exercises (Pgs. 143-145)
A. Tick (✓) the correct answers.
1. b
2. a
3. b
4. b
5. a
B. Fill in the blanks.
1. definite loop
2. 0
3. break
4. loop variable
5. while
C. Write T for True and F for False.
1. T
2. T
3. F
4. T
5. T
A.Answer the following questions.
Q.1 What do you understand by Iterative statement ?
Ans:- Iterative statements in Python allow for repetitive execution of code until a specified condition is met .
Q.2 Explain about "for loop" and "while loop" in Python.
Ans:- For Loop :- A for loop iterates through sequences like lists, strings, or ranges, executing code for each element automatically. It’s ideal when iteration count is predetermined or finite.
While Loop :- A while loop repeatedly executes code as long as its condition remains true. It requires manual updates to avoid infinite repetition, making it useful when iteration depends on dynamic conditions.
Q.3 Define List and Tuple.
Ans:- List:- A list is an ordered collection of items that can be modified . Lists are represented using square brackets.
Example:- Fruits= [ "Apple" , "Mango", "Banana" , "Grapes" ]
Tuple:- A tuple is an ordered collection of items that cannot be changed after creation . Tuple are written using round brackets .
Example :- names= ("Apple" , "Mango", "Banana" , "Grapes")
Q.4 Describe the role of the range() function in python loops . How does it control the number of iterations in a for loop ?
Ans:- The range() function is commonly used in a for loop to execute a block of code a specific number of times. It generates a sequence of numbers starting from 0 by default, incrementing by 1 unless specified otherwise, and stopping just before the given endpoint.
Q.5 What is the purpose of the else block in a for loop , and under what conditions will it executed?
Ans:- In Python, the else keyword can be used with a for loop, but it works differently from how it is used in if statements. In a for loop, the else block is executed only if the loop completes normally, without encountering a break statement.
Q.6 What are infinite loops ? How can an infinite loop be useful in real world programming scenarios ?
Ans:- An infinite loop occurs when a loop keeps running endlessly because the condition to stop the loop is never met. This can be useful in situations where you need a program to keep running, such as in a game, or monitoring systems, until a specific action occurs.
Activity Hub (Pgs. 145-146)
Give one-word answers for the following.
1. for
2. while
3. range()
4. tuple
5. loop variable
No comments:
Write CommentsPlease ask any question about gk related