+ 3
What is the else statement?
13 Antworten
+ 7
so you have a if statment:
#Created By: H4CK3R😺😺C4t😺😺
if x == 10:
print(x)#so we did are if statment we have a backup else to make sure that or “else” something else happens lets add it here:
else:
print(“Somethings wrong”)#You can use the code only if you upvote this answer.
+ 5
So in Python is useful when you add If statements.
For example
X = 4
if 6 == X:
print ("OK")
else:
print ("Error")
So else allows you to put into your code the action which program has to do if "IF" is not true
Look how it works in normal code
I hope that I helped you a bit 😊
https://code.sololearn.com/cjLtBzq3RnYs/?ref=app
https://code.sololearn.com/cpwcRrrAuHwn/?ref=app
+ 3
you have if statements that checks if an given condition is true and if that condition is false the else statement will be excecuted
+ 2
The 'else' statement is a statement that runs if the 'if' statement given if false.
+ 2
if the if statement fails no matter the condition the else statement will run the code
example in python:
if 2 == 4:
print("5")
else:
print("4")
output would be 4
to apply a condition to else statement (in python) use the elif instead
if 2 == 4:
print("4")
elif 2 == 2:
print("5")
output would be 5
+ 2
else statement in programming is a conditional statement that runs a different set of statements depending on whether an expression is true or false.
+ 2
else is a keyword which is use for decision making statement.it is always with if .
That means if condition is true then if statement is executed otherwise else statement is executed.
+ 1
It is basically a logic statement, I think.
It is based on what you need, by checking your statement with true or falsity.
Example:
If you assume Earth is round, then all say 'yes, you're right'; because Earth is actually round, so this statement/assumption made by you is true.
else all say 'no, you're wrong'.
The 'else' statement is a statement that runs if the 'if' statement given is false.
+ 1
hi
+ 1
'else' is a part of the 'if' conditional statement. You cannot write 'else' without the 'if'.
'if-else' contains a condition that returns 'true' or 'false'.
When the condition returns 'true', the code on the 'if' statement will be executed. When it returns 'false', it will execute the 'else' statement.
if (age >= 21)
access = 'granted';
else
access = 'denied';
0
yb
0
the else statement is used when there are two different possible results with different outcomes of the if statement
if NumApples <10
enough = "no"
else
enough ="yes"
0
Hello