if else in Pythpn
if...else Statement in Pythpn
The if .. else statement provides control to check the true block as well as the false block. Following is the syntax of ‘if..else’ statement.
if..else statement thus provides two possibilities and the condition determines which BLOCK is to be executed.
Example : #Program to check if the accepted number odd or even
a = int(input("Enter any number :"))
print (a, " is an even number")
print (a, " is an odd number")
Enter any number :56
56 is an even number
Enter any number :67
67 is an odd number
An alternate method to rewrite the above program is also available in Python. The complete if..else can also written as:
variable = variable1 if condition else variable 2
Example : #Program to check if the accepted number is odd or even (using alternate method of if...else)
a = int (input("Enter any number :"))
x="even" if a%2==0 else "odd"
print (a, " is ",x)
Enter any number :3
3 is odd
Enter any number :22
22 is even
Python : If else in Pythpn Program List
WAP to take two numbers and check that the first number is fully divisible by second number or not.
WAP to check the given year is leap year or not.
WAP to calculate the roots of a given quadratic equation.
Program to find the simple interest based upon number of years. If number of years is more than 12 rate
of interest is 10 otherwise 15.
Write a python program to input cost price, selling price of product from user and check whether is profit or loss and also print the Profit/loss amount
Write a python program to input a number form user and check whether number is buzz number or not.
A number is said to be Buzz Number if it ends with 7 or is divisible by 7.
Write a program to input assets, liabilities and capital of a company and test if accounting equation holds true for the given value (i.e., balanced or not).
Hint : assets == liabilities + capital
Write a program to input total debt and total assets and calculate total-debt-to-total-assets ratio (TD/TA) as Total Debt/Total Assets. Then print if the major portion of the debt is funded by assets (when TD/TA > 1) or greater portion of assets is funded by equity (when TD/TA < 1).
Write a program to calculate Debt-to-equity (D/E) ratio as [ Total Liabilities / Total shareholders' ] equity after inputting total liabilities and total shareholders' equity. And then print if an investor should invest in the company or not. A D/E ratio greater than 2.0 indicates a risky scenario for an investor.