Ch 8: Exemplar - More About Python
Ch 8: Exemplar - More About Python
Exemplar
Exercise C :-
Q - Give the output of the following codes :
(a)
Num = 0
While (NUM<10):
Num+-1
If Num == 5:
Break
print(Num,end= “,”)
Output :
(b)
For val in “String”:
If val == “i”:
Break
print(val)
print(“Over”)
Output :
Exercise D :-
Ques 1 . What is the significance of using iterations in Python?
Ans 1 . Interactions are used in Python when there is a need to repeat a ser of statements more than once
based on a certain condition. This process of repetition is called loop or iteration in programming.
A loop is thus used to repeat a block of statements a specific number of times.
The loops available in Python are:-
1. for loop
2. while loop
Ques 3. Differentiate between for and while loops with the help of an example.
Ans 3.
Example :
# Print numbers from 1 to 5 using a for-loop # Print numbers from 1 to 5 using a while loop
Output : Output :
1 1
2 2
3 3
4 4
5 5
Ques 4. What are jump statements ? Explain the jump statements in Python.
Ans 4. Jump statements are used to alter the normal flow of control in a program. These statements
"jump" the control to a different part of the program.
Jump statements in Python:
break Statement continue Statement
The break statement is used to terminate a loop The continue statement is used to skip the current
prematurely. It immediately exits the loop, iteration of a loop and move to the next iteration.
regardless of the loop's condition.
Example: Example:
Output : Output :
1 1
2 2
4
5
Explanation: The break statement exits the loop Explanation: The continue statement skips the
when i becomes 3. iteration when i equals 3, and the loop continues
with the next iteration.