In the previous article, we have learned about the concept of conditions and conditional programming in Python. In this article, we will use those concepts and write some Python programs using those concepts. these are basic programs for beginners to clear the concept.
Table of Contents
Python Program to check which number is greater
a=10
b=20
if a<20:
print(" b is greater")
else:
print("a is greater")
Take two number and check which is Smaller
num1=int(input("Enter the First Number : "))
num2=int(input("Enter the Second Number : "))
if(num1<num2):
print(num1," Is Smaller")
else:
print(num2," Is Smaller")
input()
Python Program to Check year is Leap Year or Not
year=int(input("Enter the Year number "))
if(year%100==0):
if(year%400==0):
print(year," is LeapYear")
else:
print(year," is not a LeapYear")
else:
if(year%4==0):
print(year," is LeapYear")
else:
print(year," is not a LeapYear")
input()
Basic Calculator in Python
print("Enter the Two Numbers : ")
a=int(input())
b=int(input())
print("Press + for Addition")
print("Press - for Subtraction")
print("Press * for Multiplicatin")
print("Press / for Division")
print("Press // for Division(Floor Value)")
ch=input("Enter Your Choice : ")
if(ch=='+'):
print(a," + ",b," = ",a+b)
elif(ch=='-'):
print(a," - ",b," = ",a-b)
elif(ch=='*'):
print(a," * ",b," = ",a*b)
elif(ch=='/'):
print(a," / ",b," = ",a/b)
elif(ch=='//'):
print(a," // ",b," = ",a//b)
else:
print("Invalid Choice")
input()
Check Number is perfect Square or not
import math
num=int(input("Enter the Number : "))
x=int(math.sqrt(num))
if(x*x==num):
print("Number is Perfect Square Number")
else:
print("Number is not Perfect Square Number")
input()
Program to create the Salary Slip
id=input("Enter the Employee Id : ")
name=input("Enter the Name of Employee : ")
dsg=input("Enter the Designation : ")
basic=int(input("Enter the Basic Salary: "))
l=int(input("Enter the Total Leaves : "))
lamount=basic/30*l
if(basic<=10000):
ta=basic*2/100
da=basic*3/100
hra=basic*4/100
ma=2500
else:
ta=basic*5/100
da=basic*6/100
hra=basic*7/100
ma=3500
gross=basic+ta+da+hra+ma
if(basic<=20000):
itax=0
else:
itax=(basic-20000)*5/100
net=gross-itax-lamount
print("---------Salary Slip----------")
print("Employee Id : ",id)
print("Name : ",name)
print("Designation : ",dsg)
print("------------------------------")
print("Leaves : ",l)
print("Leaves Amount : ",lamount)
print("------------------------------")
print("Ta\tDa\tHra\tMa")
print(ta,"\t",da,"\t",hra,"\t",ma)
print("------------------------------")
print("Gross Salary : ",gross)
print("Income Tax : ",itax)
print("Net Salary : ",net)
print("------------------------------")
input()
Program to check the user is valid to give the vote or not
age=int(input("Enter the age of Person : "))
if(age<18):
print("Can't vote")
else:
print("Can Vote")
input()