Page 441 - AI Ver 3.0 class 10_Flipbook
P. 441
[3]: Gender = str(input("Enter Gender (M/F): "))
Age = int(input("Enter Age: "))
if Gender == "M" and Age >= 21:
print("Eligible for Marriage")
elif Gender == "F" and Age >= 18:
print("Eligible for Marriage")
else:
print("Not Eligible for Marriage")
Enter Gender (M/F): F
Enter Age: 25
Eligible for Marriage
[4]: N1 = int(input("Enter the first number: "))
N2 = int(input("Enter the second number: "))
N3 = int(input("Enter the third number: "))
if N1 >= N2 and N1 >= N3:
print("The largest number is: ", N1)
elif N2 >= N1 and N2 >= N3:
print("The largest number is: ", N2)
else:
print("The largest number is: ", N3)
Enter the first number: 85
Enter the second number: 15
Enter the third number: 102
The largest number is: 102
Looping Statements
The process of repetition of a set of instructions based on a criterion is called a loop. There are two types of
looping statements in Python, let us study about them in detail.
The for Loop
The for loop is used to repeat a set of instructions for a fixed number of times. It means when the number of
iterations is known/definite before we start with the execution of a loop. It is therefore also known as a definite
loop. Indentation of statements is must to specify the block of statements to be repeated using for loop. Let
us understand the flow of for loop with the help of a flowchart.
There are commonly two different ways of using for loop.
Using Sequence
In this type of for loop, a sequence of values is used over which the loop iterate. The syntax to use the for loop
with a sequence is:
for <counter variable> in <sequence>:
Statements
Where,
• for is a reserved keyword.
• counter variable can be any identifier that keeps a count of the loop.
• sequence can be any value like integer, string, list etc.
• Statements always indented can be single or a block.
Advance Python (Practical) 439

