Page 52 - tp_Modula_v2.0
P. 52
On running the above program, you will get the following output:
Output
*
**
***
****
*****
Clickipedia
Never use assignment operator in place of equality operator in the test condition as it may
cause an infinite loop.
Program 9: To add first five natural numbers.
Program10.py
File Edit Format Run Options Window Help
sum = 0
a = 1
while(a<=5):
sum = sum + a
a = a + 1
print("The sum of first five natural num is", sum)
On running the above program, you will get the following output:
Output
The sum of first five natural num is 15
Recap
The statements that are used to repeat a set of instructions are called iterative or looping
statements.
Python provides two types of looping statements— for and while.
The for statement executes a simple or compound statement for a fixed number of times.
The range( ) function is an in-built function of Python.
50 Touchpad MODULAR (Version 2.0)

