Nested If Statement means to place one If inside another If Statement. Nested ifs are very common in programming. when you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement that is within the same block as the else and that is not already associated with an else.
Syntax:
if ( Expression 1 ) :
// Executes when the Expression 1 is true
if ( Expression 2 ) :
// Executes when the Expression 2 is true
This program is a Python script that prompts the user to enter three marks, then calculates the total and average of those marks, and then uses if-else statements to determine the result and grade based on the marks.
So the program is checking the student's three marks, calculating the total and average of the marks, and then determining the result and grade based on the marks and average.
# Nested If Statement in Python """ 3 Marks as Input Total Average Result If Pass Grade 90-100 A 80-89 B 70-79 C Else D """ m1 = int(input("Enter Mark-1 : ")) m2 = int(input("Enter Mark-2 : ")) m3 = int(input("Enter Mark-3 : ")) total = m1 + m2 + m3 average = total / 3.0 print("Total : ", total) print("Average : ", average) if m1 >= 35 and m2 >= 35 and m3 >= 35: print("Result : Pass") if average >= 90 and average <= 100: print("Grade : A") elif average >= 80 and average <= 89: print("Grade : B") elif average >= 70 and average <= 79: print("Grade : C") else: print("Grade : D") else: print("Result : Fail") print("Grade : No Grade")To download raw file Click Here
Enter Mark-1 : 90 Enter Mark-2 : 90 Enter Mark-3 : 90 Total : 270 Average : 90.0 Result : Pass Grade : A
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions