If-else is the basic decision making block in python. We can use one or more conditions to take a decision, if this particular block is executed or not. Every condition under if the block returns true or false. If the result is true, then all the statements under if block will be executed. But if the result is false then all the statements under else block will be executed. Both if and else statement should ends with a colon(:). and all the statements under if statement should maintain proper indentation.
Write a program to check a number is even or odd?
no=int(input("Enter A Number : ")) if(no%2==0): print(no," is an even no.") else: print(no, " is an odd no.")
Write a program to check a number is magic or not?
no=int(input("Enter A Number : ")) if(no%9==1): print(no," is a magic no.") else: print(no, " is not a magic no.")Click Here to see the if-else programs in Java.