0

Python program if and else

When I was trying Coach program runs in separate if conditions but question is given in is to use if in nested way score = int(input()) #your code goes here if score>=80: print("certificate") if score>=90: print("admitted") Nested way :- if score>=80: print("certificate") elif score>=90: print("certificate") print("admitted") else: print("nothing") Here in nested way code coach is not getting solved please identify the mistakes and tell what I am doing wrong ?

6th Oct 2021, 1:21 PM
Sayyam Jain
Sayyam Jain - avatar
3 odpowiedzi
+ 3
Hi Sayyam! Nested statement means a set of if-else statements that contain inner and outer if-else statements. It doesn't contain any elif statement. Syntax: if(): if(): else: else: And so on The code will move to inner if statement if outer if statement evaluates true. Otherwise, it passes to the outer else part. So, your code (using nested statements) needs to be like this score = int(input()) #your code goes here if score>=80: print("certificate") if score>=90: print("admitted")
6th Oct 2021, 1:37 PM
Python Learner
Python Learner - avatar
+ 1
I noticed your text on dm but for some reason I'm unable to reply you there.(I don't why) Reply: Yes, you're correct. In a if-elif-else statement, only one statement is executed while all true statements executed nested statement. You can refer this article to understand its concept clearly https://www.geeksforgeeks.org/JUMP_LINK__&&__python__&&__JUMP_LINK-if-else/
7th Oct 2021, 2:36 AM
Python Learner
Python Learner - avatar
7th Oct 2021, 8:58 AM
Sayyam Jain
Sayyam Jain - avatar