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 ?
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")
+ 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/
+ 1