Page 35 - tp_Modula_v2.0
P. 35
Program 3: To find out if the student is selected for the college or not based on the given
conditions:
1. Selected if age > 18 and marks > 65.
2. Not selected if age > 18 and marks < 65.
3. Not selected if age < 18.
Program3.py
File Edit Format Run Options Window Help
#program to check if a student is selected for college or no
name = input('Enter your name: ')
age = int(input('Enter the age of the student: '))
marks = int(input('Enter the marks of the student:'))
if (age > 18):
if (marks > 65):
print(name, 'is selected for college')
else:
print(name, 'is not selected for college')
else:
print(name, 'is too young for college')
On running the above program, you will get the following output:
Output
Enter your name: Pankaj
Enter the age of the student: 19
Enter the marks of the student:89
Pankaj is selected for college
Enter your name: Pankaj
Enter the age of the student: 15
Enter the marks of the student:89
Pankaj is too young for college
IF…ELIF…ELSE LADDER
The if…elif…else ladder is another type of if statement. It helps us to test multiple conditions
and follows a top-down approach. In this, as soon as the condition of the if evaluates to be true,
the indented block associated with that ‘if’ is executed, and the rest of the ladder is avoided.
If none of the conditions evaluates to true, then the final else statement gets executed.
Conditional Statements in Python 33

