CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM 1 : ARITHMETIC OPERATIONS
AIM
Write a program to accept two integer values from the user and perform all basic arithmetic
operations
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept two values and store it in A and B
STEP 3 : Compute Sum = A+B , Diff = A-B , Product = A*B , Quo = A / B ,
Rem = A%B
STEP 4 : Print the values in identifiers Sum, Diff, Product , Quo and Rem
STEP 5 : End the process
FLOW CHART
START
ACCEPT A & B
COMPUTE
SUM = A+B
DIFF = A-B
PRO = A*B
QUO = A /B
REM = A%B
DISPLAY SUM ,
DIFF , PRO ,
QUO , REM
STOP
CODE :
A= int(input(" Enter the first number : "))
B= int(input(" Enter the second number : "))
SUM = A+B
DIFF=A-B
Page 1 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PRO=A*B
QUO=A/B
REM =A%B
print ( "\n\t The sum of ", A , " and ", B , " is ",SUM)
print ( "\n\t The difference of ", A , " and ", B , " is ",DIFF)
print ( "\n\t The product of ", A , " and ", B , " is ",PRO)
print ( "\n\t The quotient of ", A , " and ", B , " is ",QUO)
print ( "\n\t The remainder of ", A , " and ", B , " is ",REM)
OUTPUT
Enter the first number : 45
Enter the second number : 7
The sum of 45 and 7 is 52
The difference of 45 and 7 is 38
The product of 45 and 7 is 315
The quotient of 45 and 7 is 6.428571428571429
The remainder of 45 and 7 is 3
Page 2 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM : 2 SIMPLE INTEREST CALCULATION
AIM
Write a program that accepts Principle, Amount, Rate and Time from the user and calculate
the simple interest
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept principle amount, rate and time as P, R and T from the user
STEP 3 : Compute SI = (P*R*T)/100
STEP 4 : Display SI as Simple Interest
STEP 5 : End the process
FLOW CHART
START
Accept principle amount, rate
and time as P, R and T
SI =(P*R*T)/100
DISPLAY SI
STOP
CODE
P= float(input("\n\t Enter the Principle amount :"))
R= float(input("\n\t Enter the Rate of Interest :"))
T= float(input("\n\t Enter the Time :"))
SI = (P*R*T)/100
print ( "\n\t The Simple Interest is ",SI)
OUTPUT
Enter the Principle amount :2500
Enter the Rate of Interest :12
Enter the Time :5
The Simple Interest is 1500.0
Page 3 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM : 3 FINDING THE LARGEST OF TWO NUMBERS
AIM
To write a python Program to Input two numbers and display the largest number.
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept Num1,num2
STEP 3 : Check if num1>num2 ,if so print num1 “is greater” else do step 4 goto step 5
STEP 4 : Print num2 “is greater”
STEP 5 : End the process
FLOW CHART
START
INPUT NUM1,NUM2
YES PRINT NUM1
“IS GREATER
IF THAN NUM2”
NUM1>NUM2
NO
PRINT NUM2 “IS
GREATER THAN
NUM1’
STOP
CODE
#Python Program to Input two numbers and display the larger / #smaller number.
num1 = int (input ("Enter the first number: "))
num2 = int (input ("Enter the second number: "))
Page 4 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
if num1 > num2:
print (num1,"is larger than", num2)
else:
print (num1,"is smaller than", num2)
OUTPUT:
Enter the first number: 21
Enter the second number: 5
21 is larger than 5
Page 5 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM : 4 SALARY CALCULATION
AIM
Write A python program to input the name and basic salary of an employee. Calculate and
display the name, gross salary and net salary of the employee when :
DA : 30% of basic
HRA : 18% of basic
PF : 12.5% of basic
GROSS : basic + da + hra
NET : GROSS - PF
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept name and basic salary from the user
STEP 3 : Compute DA = 0.30 * basic , HRA = 0.18 * basic, PF = 0.125 * basic
STEP 4 : Compute GROSS = basic + DA + HRA ; NET = GROSS – PF
STEP 5 : Display Name, GROSS Salary and Net Salary
STEP 6 : End the process
FLOWCHART :
START
INPUT NAME, BASIC
COMPUTE
DA=0.30 * BASIC , HRA = 0.18 * BASIC
PF = 0.125 * BASIC, GROSS = BASIC + DA + HRA
NET = GROSS-PF
DISPLAY NAME, GROSS
SALARY & NET SALARY
STOP
CODE :
NAME=input("\n\t Enter the Name :")
BASIC=float(input("\n\t Enter the Basic Salary :"))
Page 6 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
DA=0.30 * BASIC
HRA = 0.18 * BASIC
PF = 0.125 * BASIC
GROSS = BASIC + DA + HRA
NET = GROSS-PF
print("\t The name of the Employee is " , NAME)
print("\t The Gross Salary is " , GROSS)
print("\t The Net Salary " , NET)
OUTPUT :
Enter the Name :Arun
Enter the Basic Salary :9500
The name of the Employee is Arun
The Gross Salary is 14060.0
The Net Salary 12872.5
Page 7 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM : 4LEAP YEAR OR NOT
AIM
Write a Python program to check whether a user defined year is a leap year or not.
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept year from the user
STEP 3 : Check if (year%400 == 0 or year%4 == 0 ) and ( year%100 != 0))), if so goto
Step 4, otherwise goto step 5
STEP 4 : Display “It is a Leap year” ; Goto step 6
STEP 5 : Display “It is NOT a Leap year”
STEP 6 : End the process
FLOWCHART :
START
INPUT YEAR
NO
IS IS YEAR%4==0
YEAR%400==0 NO
YES
YES
IS
YEAR%100!=0
YES
NO
DISPLAY ‘IT DISPLAY ‘IT
IS A LEAP IS NOT A
YEAR’ LEAP YEAR’
STOP
Page 8 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
CODE
input_year = int(input("\n\t Enter the Year to be checked: "))
if (( input_year%400 == 0)or (( input_year%4 == 0 ) and ( input_year%100 != 0))):
print(input_year ," is Leap Year" )
else:
print( input_year," is Not the Leap Year" )
OUTPUT
Enter the Year to be checked: 2022
2022 is Not the Leap Year
Enter the Year to be checked: 2020
2020 is Leap Year
PROGRAM : 5 ROOTS OF A QUADRATIC EQUATION
AIM
Write a Python program to find the roots of the quadratic equation.
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept the three coefficients as a, b, c from the user
STEP 3 : Check if a == 0: then display("Invalid") ; goto STEP 6
STEP 4 : Compute d as b * b - 4 * a * c
STEP 5 : Compute sqrt_val = math.sqrt(abs(d))
STEP 6 : Check if d > 0:then
i) Display "Roots are real and different "
ii) Display the first root as -b + sqrt_val/(2 * a)
iii) Display the second root as -b - sqrt_val/(2 * a)
STEP 7 : Check if d == 0: then
i) Display "Roots are real and same"
ii) Display the root as -b / (2*a)
STEP 8 : Check if d <0
i) Display "Roots are complex"
ii) Display first root as- b / (2*a), and imaginary part as sqrt_val
iii) Display second root as - b / (2*a), and imaginary part as sqrt_val
STEP 6 : End the process
Page 9 of 14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
FLOWCHART :
START
Accept A, B, C as
coefficient values
Is YES
a==0
NO
Compute d = b * b - 4 * a * c
Compute sqrt_val = math.sqrt(abs(d))
Display "Roots are real and different "
YES
Is Display ‘1st root’ = -b + sqrt_val/(2 * a)
d>0 Display ‘2nd root’ = -b - sqrt_val/(2 * a)
NO
YES Display "Roots are real and same "
Is Display ‘ root’ = -b/(2 * a)
d==0
NO
YES
Is Display "Roots are real and imaginary "
D<0 Display ‘1st root’ = -b /(2 * a) & -i= sqrt_val
Display ‘2nd root’ = -b /(2 * a) & +i= sqrt_val
NO
STOP
Page 10 of
14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
CODE
import math
a=int(input ("\n\t Enter the first coefficient :"))
b=int(input ("\n\t Enter the second coefficient :"))
c=int(input ("\n\t Enter the third coefficient :"))
if a == 0:
print("Invalid")
else:
d=b*b-4*a*c
sqrt_val = math.sqrt(abs(d))
if d > 0:
print("Roots are real and different ")
print((-b + sqrt_val)/(2 * a))
print((-b - sqrt_val)/(2 * a))
elif d == 0:
print("Roots are real and same")
print(-b / (2*a))
else: # d<0
print("Roots are complex")
print(- b / (2*a), " + i", sqrt_val)
print(- b / (2*a), " - i", sqrt_val)
OUTPUT
Enter the first coefficient :1
Enter the second coefficient :2
Enter the third coefficient :1
Roots are real and same-1.0
Enter the first coefficient :2
Enter the second coefficient :2
Enter the third coefficient :1
Roots are complex-0.5 + i 2.0
Enter the first coefficient :5
Enter the second coefficient :6
Enter the third coefficient :7
Roots are complex
-0.6 + i 10.198039027185569
-0.6 - i 10.198039027185569
Page 11 of
14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
PROGRAM : 6 ELECTRICITY BILL GENERATION
AIM
The electricity Board charges for electricity from their consumers according to the
units consumed ( per month ) as per the following tariff :
UNITS CONSUMED CHARGES
Up to 100 units Rs 4.80 /unit
More than 100 units and up to 300 units Rs 6.30 / unit
More than 300 units and up to 500 units Rs 7.80 / unit
More than 500 units Rs 8.50 / unit
Write a Python program to input the name of the consumer, consumer number , month
and units consumed. Calculate and display the electricity bill with all the details..
ALGORITHM
STEP 1 : Start the process
STEP 2 : Accept the consumer number as cn, consumer name as cname, month as mon
and units as units from the user
STEP 3 : Check if units<=100 then compute p= units*4.80; goto step 7
STEP 4 : Otherwise check if units >100 and units <=300 ,
then compute p=480+(units-100)*6.30 ; goto step 7
STEP 5 : Otherwise check if units >300 and units <=500 ;
Then compute p=480+1260+(units-300)*7.80 ; goto step 7
STEP 6 : otherwise compute p=480+1260+1700+(units-500)*8.50
STEP 7 : Display “The Consumer Number is ",cn
Display “The Consumer Name is ",cname
Display “ The month for which bill is generated ",mon
Display “ The Bill Amount is ",p
STEP 8 : End the process
Page 12 of
14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
FLOWCHART
START
Accept cn, Cname, mon and
units from user
Is YES
Compute p=units*4.80
units<=100
NO
Is YES
300>=units Compute p=480+(units-100)*6.30
>100
NO
Is YES
500>=units Compute p=480+1260+(units-300)*7.80
>300
NO
Compute p=480+1260+1700+(units-500)*8.50
Display cn, Cname, mon
and Bill amount to user
START
Page 13 of
14
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
CODE
# A program to display the electricity bill
cn = input ( "\t Enter the Consumer Number :")
cname = input("\t Enter the Consumer Name :")
mon = input("\t Enter the Month for which bill is generated : ")
units = int(input("\t Enter the units consumed :"))
if units<=100:
p=units*4.80
elif units >100 and units <=300 :
p=480+(units-100)*6.30
elif units >300 and units <=500 :
p=480+1260+(units-300)*7.80
else:
p=480+1260+1700+(units-500)*8.50
print ("\n\t The Consumer Number is ",cn)
print ("\n\t The Consumer Name is ",cname)
print ("\n\t The month for which bill is generated ",mon)
print ("\n\t The Bill Amount is ",p)
OUTPUT
Enter the Consumer Number :12
Enter the Consumer Name :Aarti
Enter the Month for which bill is generated : July
Enter the units consumed :1237
The Consumer Number is 12
The Consumer Name is Aarti
The month for which billis generated July
The Bill Amount is 9704.5
Page 14 of
14