If Condition Using if,elif,else
In this Example we are defining if ,elif and else statement. First the if condition is tested and if found true the next block is executed , else elif condition is tested and if found true the elif block is executed. If all fails else block is executed.
In this Example we are defining if ,elif and else statement. First the if condition is tested and if found true the next block is executed , else elif condition is tested and if found true the elif block is executed. If all fails else block is executed.
Example
num = float(input("Enter a number:
"))
if num > 0:
print(num, "is a Positive number")
elif num == 0:
print("Zero")
else:
print(num, "is a Negative number")
Result
Using Nested if
Statement.
Here we define if with if statement.
Example
num = float(input("Enter a number:
"))
if num >= 0:
if num == 0:
print("Zero")
else:
print(num,"is a Positive number")
else:
print(num,"is a Negative number")
Result
No comments:
Post a Comment