Page 248 - Ai_V1.0_Class9
P. 248
for var in range(1,10,2): 1,3,5,7,9
print(var,end=",")
for count in range(1,10): 1,2,3,4,5,6,7,8,9
print(count,end=",")
for var in range(10): 0,1,2,3,4,5,6,7,8,9
print(var,end=",")
for var in range(5,0,–1): 5,4,3,2,1
print(var,end=",")
for var in range(5,5): No output
print(var,end=",")
for var in range(5,3): No output
print(var,end=",")
#Program to generate alternate numbers for the given range enter starting value: 5
starts=int(input("enter starting value: ")) enter ending value: 10
ends=int(input("enter ending value: ")) 5,7,9,
for var in range(starts, ends+1,2):
print(var,end=",")
Brainy Fact
Comparison operators (<, >, <=, >=, !=, ==) and logical operators (and, or) returns True or
False.
The while Loop
The while loop is used to repeat a set of instructions as long as the condition is true. It means when the number of
iterations are not fixed/indefinite before we start with the execution of a loop. Therefore, it is known as an indefinite
loop. Indentation of statements is must to specify the block of statements to be repeated using while loop.
This loop is also called an entry-controlled loop as it checks for the condition in the beginning. If the condition
is 'True' then the body of the loop will be executed. If the condition is 'False' then it will not be allowed to enter
within the loop and it stops. The syntax of the while loop is:
while <condition>
Statements
Where,
• while is a keyword.
• condition is a criterion to repeat the instructions. The instructions repeat until the condition is 'True'. As soon
as the condition is 'False', the control exits from the loop.
246 Artificial Intelligence Play (Ver 1.0)-IX

