Home > Software design >  i dont know where im wrong in this python code of conditional statements using if elif and else
i dont know where im wrong in this python code of conditional statements using if elif and else

Time:05-13

this is what I'm trying to do but it keeps on saying something is wrong in line 15

CodePudding user response:

There is an error in your code because you can not have an elif statement after an else statment.

Your code

if #something:
   #something
else #something:
   #something
elif #something:
   #something

Correct way:

if #something:
   #something
elif #something:
   #something
else #something:
   #something

CodePudding user response:

the problem is nexted if and else should be intended other wise the first else goes with first else

avarage_grade =7
attendance=1
if (avarage_grade>=6):
    if(attendance>=0.8):
        print('student has passed')
    else: #here
        print("student has failed due to low attendance rate") # and here
elif(attendance>0.8):
    print("student has failed due to low avarage_grade")
else:
    print("student has failed due to low avarage_grade and low attendance rate")

also please post your code also... for future anyone to see

  • Related