#### 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.

Syntax:

`if <condition>:statements-block 1else:statements-block 2`

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 :"))if a%2==0:print (a, " is an even number")else:print (a, " is an odd number")`

Output 1:

Enter any number :56

56 is an even number

Output 2:

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:

Syntax:

`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)`

Output 1:

Enter any number :3

3 is odd

Output 2:

Enter any number :22

22 is even

Qus. 1 : <p>What will be the output after following statements?</p><pre>x = 2<br>if x &lt; 5:<br>&nbsp; &nbsp; &nbsp;print(x)<br>else:<br>&nbsp; &nbsp; pass</pre><div><br></div>

1. 2 3 4
2. 1 2 3 4
3. 2
4. None of These
Qus. 2 : <p>What does the following code print ?</p><pre><span style="font-size: 14px;">if 2 + 5 == 8:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print("TRUE")<br></span><span style="font-size: 14px;">else:<br></span><span style="font-size: 14px;">&nbsp; &nbsp; print("FALSE")<br></span><span style="font-size: 14px;">print("TRUE")</span></pre><div><br></div>

1. TRUE
2. TRUE FALSE
3. TRUE TRUE
4. FALSE TRUE
Qus. 3 : Can we write if / else into one line in python?

1. Yes
2. No
3. if / else not used in python
4. None of the above.

#### Programs

python Program to obtain temperature in Celsius and convert it into Fahrenheit

pythoon program to read todays date only date Part from user Then display how many days are left in the current month

python program to print the area of circle when radius of the circle is given by user

python program to print the volume of a cylinder when radius and height of the cylinder is given by user

python program that asks your height in centimeters and converts it into foot and inches

python program accept three side of triangle and find area of a triangle

python program to input principle amount,rate time and calculate simple interes

python program to read a number in n and prints n2 n3 n4

python program to calculate compound simple interest after taking the principle rate and time

python program to take two numbers and check that the first number is fully divisible by second number or not

python program which take value of x y z from the user and calculate the equation

python program to take the temperatures of all 7 days of the week and displays the average temperature of that week

python program to check the given year is leap year or not

python program that searches for prime numbers from 15 through 25

python program to test if given number is prime or not

python program to compute the result when two numbers and one operator is given by user

python program to calculate the roots of a given quadratic equation.

python program to input a digit and print it in words

python program to check whether square root of a given number is prime or not

python program to print first n odd numbers in descending order.

python program to find the average of the list of the numbers entered through keyboard

python program to find the largest number from the list of the numbers entered through keyboard

python program to find the sum of n natural numbers

python program to find the sum of first n even numbers

python program to find the sum of first n odd numbers.

python program to generate a list of elements of Fibonacci Series

python program to find simple interest based upon number of years

python program to input any choice and to implement the following

python program to input any number and to print all natural numbers up to given number

python program to input any number and to find sum of all natural numbers up to given number

python program to input any number and to find reverse of that number

python program to input any string and count number of uppercase and lowercase letters

python program to obtain three numbers and print their sum

Python program to obtain length and breath of a rectangle and calculate its area

python program to calculate body mass index of a person

python program to input a number and print its cube

python program to input two number and swap them

python program to input three number and swap 3 numbers

python program to read 3 numbers in 3variables and swap first two variables with the sums of first and second

python program to input a single digit and print a 3 digit number

python program to accept a integer number and find its sum of digit

python program to count the number of digits in given number

python program to find the factorial value of given number

python program to print factor of given number

python program to check given number is composite number or not

python program to find the largest digit of a given number

python program to find the smallest digit of a given number

python program to print table of entered number

python program to calculate the compound interest

python program to find sale price of an item with given price and discount

python program to calculate the sum of odd numbers divisible by 5 from the range 1 to 100

Python Program to Calculate the Area of a Triangle

python program for addition of two times in hour and minute format

python program for addition of two times in hour minute and second format

python program to check number is positive negative or zero

python program to check number is even or odd

python program to check where is profit or loss

python program to check number is buzz number or not

python program to input assets liabilities and capital then check accounting equation means balanced or not

python program to input total debt and total assets and calculate total debt to total assets ratio and check whether major funded by assets or equity

python program to calculate debt to equity check whether it is risky scenario for investor or not

python program to find the difference between greatest and smallest digits presents in the number

python program to print the frequency of digits present in given number

python program to print Floyds triangle

python program to check whether given number is Armstrong or not

python program to find all prime numbers up to given number

python program to convert decimal number to binary

Python program to convert binary to decimal

python program to print quotient

Python program to calculate simple interest

Python program to calculate area and perimeter of a parallelogram

Python program demonstrating working with power operator

Python program of division operator

Python program of modulus

Python program convert dollars in Rupee

Python program to convert kilometers to miles

Python program to convert the distance in feet to inches yards and miles

Python credit card program

Python program to print absolute value of number provided by the user

Python program to check divisibility of a number

Python program to print the largest number

Python program to display menu to calculate area of square or rectangle

Python program to print larger number using swap

Python program to calculate electricity bill

Python program to input three number and print in ascending order

Python program to check character is alphabetic character or not

Python program to print letters of word

Python program to print ASCII code for entered message

Python program to print first ten mersenne numbers

python program to obtain x y z from user and calculate expression

python program that reads a number of seconds and prints it in form mins and seconds

python program to take year as input and check if it is a leap year or not

python program to take two numbers and print if the first number is fully divisible by second number or not

python program to take a 2 digit number and then print the reversed number

python program to take a 3 digit number and then print the reversed number

python program to take two inputs for day month and then calculate which day of the year

python program that asks a user for a number of years and then prints out the number of days hours minutes and seconds

python program that inputs an age and print age after 10 years

python program to find a side of a right angled triangle whose two sides and an angle is given

python program to calculate the radius of a sphere whose area is given

python program to calculate the area of an equilateral triangle

python program to input the radius of a sphere and calculate its volume

python program to calculate amount payable after simple interest

python program to input length of three sides of a triangle Then check if these sides will form a triangle or not

python program to input 3 sides of a triangle and print whether it is an equilateral scalene or isosceles triangle

python program to Print numbers from 11 to N When the number is a multiple of 3 print Tipsy when it is a multiple of 7 print Topsy

python program to input N numbers and then print the second largest number

python program to input list of numbers and find those which are palindromes

python program to place and the most significant digit of number

Python program to print every integer between 1 and n divisible by m Also report whether the number that is divisible by m is even or odd

python program to find the LCM of two input numbers

python program to find GCD of 2 number

python program to check number is perfect number or not

python program to check number is special or not

python program to print first n perfect numbers

Python program using if Elif else statement to find the number of days present in a month

python program to print all buzz numbers between 1 to n

Python program to input 3 numbers and check all are same or not

python program to input 3 numbers from user and check these are unique numbers are not

python program to input 2 integer number and check where they are same of different number

Python function which takes list of integers as input and finds the followings

Python program to print all the prime numbers in the given range

Python program to print the sum of series

python program to input the time in second and convert into hours minute and seconds

python program to obtain the marks in computer of some student and find mean median and mode

Write a Python code to calculate and display the value of Sine 45° and Cosine 30°

python program to input three unequal numbers and display the greatest and the smallest number

python program to accept marks of English math and science and display the appropriate stream allotted to the candidate

python program to calculate income tax based on condition

python program to calculate volume of cuboid cylinder and cone based on user choice

python program to display the first ten terms of the following series 2 5 10 17

python program to find the sum of first ten terms of the series

python program to find the smallest digit of the input number

python program to check whether it is a prime number or not If it is not a prime then display the next number that is prime

python program to accept the Base and Perpendicular and find the Hypotenuse

python program to accept three side of triangle and find its area by using Herons Formula

python program to accept side of Equilateral Triangle and find its area

Python program to check whether dart hit inside board or outside