Introduction to python
Collection in Python
Object Oriented python
Python With MYSQL And Excel
Python GUI
Programs in Python
- Swap two number
- Calculate the area
- Even Odd or Zero
- Largest ,Middle and Smallest Number
- Calculate Telephone Bill
- Print Table of The given Number
- Factorial of the number
- Reverse and check number is palindrome
- check number is prime , armstrong
- Program to Print the given patterns
- Guess A Number Game using Random
If Else in Python
In Python we can compare two values like following
a)== (compares if two values are equals)
b)!= (not equal to)
c)> and >= ( greater than and greater than equal to).
d)< and <= (less than and less than equal to)
General syntax of if using python is following.
if 10>2:
print("yes if is true")
Remember indentation is important in python it does not need braces as c or java
program to check input number is zero , even or odd using if only (without else)
n=int(input("enter the number"))
if n==0:
print("given number is zero")
if n%2==0 and n!=0:
print("given number is even")
if n%2==1:
print("given number is odd")
In this example second if has two conditions with and
python uses “and” instead of && like c or java. Similarly or is used in place of || as in c or java.
If Else in Python: As we know else is the optional part of else
if part executes if the condition is true while else part executes if the condition false.
In this scenario at least one part either if or else always executes.
Program to check if the number is devisible of 100
n=int(input("enter the number"))
if n%100==0:
print("number is divisble ")
else:
print("number is not divisible by 100")
simmilarly multiple if or if else ladder may also be used as per requirements.