Tamilar marabu
Tamilar marabu
Tamilar marabu
NO:1a
Electricity Billing
DATE:
AIM:
ALGORITHM:
Step1: Start.
Step2: Read the previous unit and current unit.
Step 3: Calculate the used units by subtracting the current unit and previous unit.
Step4: Calculate the Electricity bill from the used units.
Step 5: Print the amount of electricity bill.
Step6: Stop.
PSEUDOCODE:
RESULT:
Thus, the flowchart for the electricity billing is developed.
EX. NO:1b.
Retail Shop Billing
DATE:
AIM:
ALGORITHM:
Step1: Start.
Step2: Read the barcode of the product.
Step3: Display the product name and the amount.
Step 4: Check if more products is available, if available go to Step 2, otherwise go to Step 5.
Step5: Calculate the total cost of the products.
Step6: Print total cost.
Step7: Stop.
PSEUDOCODE:
RESULT:
Thus, the flowchart for retail shop billing is developed.
EX. NO:1c.
Sin Series
DATE:
AIM:
ALGORITHM:
Step1: Start
Step2: Read x and n.
Step3: Print x and n.
Step 4: Convert x values into radian using formula x = x * 3.1412/180.
Step5: Substitute t=x and sum=x.
Step 6: Set the for loop for doing the calculation as initialize i to 1 and check i is less thann+1and increment i
by 1.
Step 7: Calculate t=(t*pow(-1),(2*i-1))*x*x)/(2*i*(2*i+1).
Step8: Calculate sum = sum + t.
Step9: Print sum.
Step10: Stop
PSEUDOCODE:
READ x, n
PRINT x, n
CONVERT x =x * 3.1412/180
SUBSTITUTE t=x, sum=x
FORi=1; i<n+1;i++
t= (t*pow (-1), (2*i-1))*x*x)/(2*i*(2*i+1).
sum = sum + t
END FOR
PRINT sum
FLOWCHART:
RESULT:
Thus, the flowchart for the sine series is developed.
EX. NO:1d
Weight of a Motorbike
DATE:
AIM:
ALGORITHM:
Step1: Start.
Step2: Read the size of the motor bile in cc.
Step3:Check whether the size of the motor bike is less than or equal to 300 cc, if so, Print Average weight is 350
pounds otherwise go to step 4.
Step4: Check whether the size of the motor bike is less than or equal to 500 cc, if so, Print Average weight is 410
pounds otherwise go to step 5.
Step5: Check whether the size of the motor bike is less than or equal to 900cc, if so, Print Average weight is 430
pounds otherwise go to step 6.
Step6:Check whether the size of the motor bike is equal to 1100 cc, if so, Print Average weight is 500 pounds
otherwise go to step 7.
Step 7: Print Average weight is 600 pounds.
Step 8: Stop.
PSEUDOCODE:
READ size in cc
IF size<=300 THEN
PRINT Average weight = 350 pounds
ELSEIF size <=500 THEN
PRINT Average weight = 410 pounds
ELSEIF size <=900 THEN
PRINT Average weight = 430 pounds
ELSEIF size =1100 THEN
PRINT Average weight=500pounds
ELSE
PRINT Average weight=600pounds
ENDIF
FLOWCHART:
RESULT:
Thus, the flowchart for finding the weight of the motor bike is developed.
EX. NO:1e
Weight of a steel bar
DATE:
AIM:
ALGORITHM:
Step1:Start.
Step2:Read the diameter in mm and length of the steel bar.
Step3:Check whether the length is in meter if so, calculate weight as diameter x diameter x length and divide it by
162, otherwise go to step4.
Step 4: calculate weight as diameter x diameter x length and divide it by 533.
Step5: Print the weight.
Step6: Stop.
PSEUDOCODE:
RESULT:
Thus, the flowchart for finding the weight of a steel bar is developed.
EX. NO:1f
Compute Current Three Phase AC Circuit
DATE:
AIM:
ALGORITHM:
Step1: Start.
Step2: Get the value of voltage, resistance, current and power factor.
Step3: Compute the electric current by multiplying voltage, resistance, current and power factor with 3.
Step 4: Print the calculated electric current.
Step5: Stop.
PSEUDOCODE:
RESULT:
Thus, the flowchart for computing the electric current in three phase AC circuit is developed.
EX. NO:2a
Exchange the values of two variables
DATE:
AIM:
To write a Python Program to exchange the value of two variables.
ALGORITHM:
STEP 1: Start the program
STEP2: Enter two variables and assign value for it(x, y)
STEP3: simply exchange the variables(y, x) and assign it to variables(x, y)
STEP 4: print ‘x’ value
STEP5: print ‘y’ value
STEP6: End the program
PROGRAM:
x=5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
OUTPUT:
x = 10
y=5
RESULT:
Thus the Python Program to exchange the value of two variables was written and executed successfully.
EX. NO:2b
circulate the values of n variables
DATE:
AIM:
To write a Python Program to circulate the values of n variables.
ALGORITHM:
STEP1: Start the program
STEP2: Read the total number of values
STEP3: Enter the values
STEP4: Append the value in the list1
STEP5: Print the list1 of elements
STEP6: check the range of values and pop the first element from the list1 and append it at the last in the
list1
STEP7: Continue until range (0 to 3) exit.
STEP8: End the program.
PROGRAM:
no_of_terms = int(input("Enter number of values:"))
list1 = []
for val in range(0,no_of_terms,1):
ele=int(input("Enter integer:"))
list1.append(ele)
print("Circulating the elements of list",list1)
for val in range(0,no_of_terms,1):
ele = list1.pop(0)
list1.append(ele)
print(list1)
OUTPUT:
Enter number of values : 4
Enter integer : 5
Enter integer : 3
Enter integer : 6
Enter integer : 1
Circulating the elements of list [5, 3, 6, 1]
[3, 6, 1, 5]
[6, 1, 5, 3]
[1, 5, 3, 6]
[5, 3, 6, 1]
RESULT:
Thus the Python Program to circulate the values of n variables was written and executed successfully.
EX. NO:2c
AIM:
To write a Python Program to find the distance between two points.
ALGORITHM:
PROGRAM:
import math
p1=[4, 0]
p2=[6, 6]
distance=math.sqrt(((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2))
print(distance)
OUTPUT:
6.324555320336759
RESULT:
Thus the Python Program to find the distance between two points was written and executed successfully.
EX. NO:3a
Number series
DATE:
AIM
ALGORITHM
PROGRAM:
a=0
b=1
n=int(input("Enter the number of terms in the sequence:"))
print(a,b,end="")
while(n-2):
c=a+b
a,b=b,c
print(c,end="")
n=n-1
OUTPUT:
Enter the number of terms in the sequence: 8
0 1 1 2 3 5 8 13
RESULT:
Thus the python program to print number series was written and executed successfully.
EX. NO:3b
Number pattern
DATE:
AIM:
ALGORITHM:
STEP1: Start
STEP4: Using for loop print str (i) values i times in every iteration
PROGRAM:
for i in range(10):
print(str(i)*i)
OUTPUT:
1
22
333
4444
55555
666666
7777777
88888888
999999999
RESULT:
Thus the python program to print number pattern was written and executed successfully.
EX. NO:6.a
Factorial
DATE:
AIM:
To write a Python Program to find factorial of a given number using function.
ALGORITHM:
STEP1: Start the program
STEP2: Define a function name factorial ()
STEP3: Assign or Get the value of n from the user.
STEP3: Return 1 if n==1 or 0(since 1! &0! is 1)
STEP4: Else compute n * factorial (n - 1)
STEP5: Print the factorial value for a given number
STEP6: End the program
PROGRAM:
def factorial(n):
return 1 if(n==1 or n==0) else n *factorial(n - 1);
num = 5;
print("Factorial of",num,"is",
factorial(num))
OUTPUT:
Factorial of 5 is 120
RESULT:
Thus the Python Program to find factorial of a given number using function was written and executed
successfully.
EX. NO:6.b.
Largest numbers in a list
DATE:
AIM:
To write a Python Program to find two largest numbers in a list using functions.
ALGORITHM:
Step1: Start the program
Step2: Take a list of values
Step3: using max () function finds first largest number
Step4: using remove () function remove first largest largest function
Step5: Again using max () function finds second largest number
Step6: print the two largest number
Step7: End the program
PROGRAM:
integers = [1, 16, 3, 39, 26, 4, 8, 16]
copy_of_integers = integers[:]
largest_integer = max(copy_of_integers)
copy_of_integers.remove(largest_integer)
second_largest_integer = max(copy_of_integers)
print(largest_integer)
print(second_largest_integer)
OUTPUT:
39
26
RESULT:
Thus the Python Program to find two largest numbers in a list using functions was written and executed
successfully.
EX. NO:6.c.
AIM:
To write a Python Program to find area of shape using functions.
ALGORITHM:
PROGRAM:
def areacalculator():
_input_ = input("Enter the shape you want to calculate area of: ")
area = 0
pie = 3.14
if _input_ == "Square":
side = int(input("Enter the value of side: "))
area = area + (side ** 2)
elif _input_ == "Circle":
radius = int(input("Enter the value of radius: "))
area = area + (2 * pie * radius)
elif _input_ == "Rectangle":
length = int(input("Enter the value of length: "))
width = int(input("Enter the value of length: "))
area = area + (length * width)
elif _input_ == "Triangle":
base = int(input("Enter the value of base: "))
height = int(input("Enter the value of height: "))
area = area +(0.5 * base * height)
else:
print ("Select a valid shape")
print ("%.2f" % area)
areacalculator()
OUTPUT:
Enter the shape you want to calculate area of: Square
Enter the value of side: 3
9.00
Enter the shape you want to calculate area of: square
Select a valid shape
0.00
RESULT:
Thus the Python Program to find area of shape using functions was written and executed successfully.
EX. NO:7.a.
String Reverse
DATE:
AIM:
ALGORITHM:
PROGRAM:
def my_function(x):
return x[::-1]
mytxt = my_function("I wonder how this text looks like backwards")
print(mytxt)
OUTPUT:
sdrawkcabekilskooltxetsihtwohrednow I
RESULT:
Thus the Python Program to reverse a string was written and executed successfully.
EX. NO:7.b.
Palindroms
DATE:
AIM:
ALGORITHM:
PROGRAM:
string=input(("Enter a string:"))
if(string==string[::-1]):
print("The string is a palindrome")
print(string[::-1])
else:
print("Not a palindrome")
print(string[::-1])
OUTPUT:
Enter a string:qwert
Not a palindrome
Trewq
Enter a string:malayalam
The string is a palindrome
Malayalam
RESULT:
Thus the Python Program to find palindrome for the given string was written and executed successfully.
EX. NO:7.c.
Character Count
DATE:
AIM:
To write a Python Program to count the given character.
ALGORITHM:
PROGRAM:
message = 'python is popular programming language'
print('Number of occurrence of p:', message.count('p'))
OUTPUT:
Number of occurrence of p: 4
RESULT:
Thus the Python Program to count the given character was written and executed successfully.
EX. NO:7.d.
Replacing Characters
DATE:
AIM:
ALGORITHM:
STEP3: Get a replace character from the user and replace the character using replace ()
PROGRAM:
a_string = "aba"
a_string = a_string.replace("a", "b")
print(a_string)
OUTPUT:
bbb
RESULT:
Thus the Python Program to replace the character was written and executed successfully.
EX. NO:8.a.
Numpy
DATE:
AIM:
To implement Numpy using written modules and Python Standard Libraries.
ALGORITHM:
PROGRAM:
import numpy as np
a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a)
#Slicing in array
print(a.shape)
b = a[1:, 2:]
print(b)
OUTPUT:
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
(3, 4)
[[ 7 8]
[11 12]]
RESULT:
Thus implemented Numpy using written modules and Python Standard Libraries was written and executed
successfully.
EX. NO:8.b
Pandas
DATE:
AIM:
ALGORITHM:
PROGRAM:
import pandas as pd
S = pd.Series([11, 28, 72, 3, 5, 8])
print(S)
OUTPUT:
0 11
1 28
2 72
3 3
4 5
5 8
Dtype : int64
RESULT:
Thus implemented pandas using written modules and Python Standard Libraries was written and executed
successfully.
EX. NO:8.c.
Matplotlib
DATE:
AIM:
ALGORITHM:
STEP4: Plot and name them using plt.xlabel () and plt.ylabel () functions
PROGRAM:
from matplotlib import pyplot as plt
plt.bar([0.25,1.25,2.25,3.25,4.25],[50,40,70,80,20],
label="BMW",color='r',width=.1)
plt.bar([.75,1.75,2.75,3.75,4.75],[80,20,20,50,60],
label="Audi", color='b',width=.5)
plt.legend()
plt.xlabel('Days')
plt.ylabel('Distance(kms)')
plt.title('Information')
plt.show()
OUTPUT:
RESULT:
Thus implemented matplotlib using written modules and Python Standard Libraries was written and
executed successfully.
EX. NO:8.d.
Scipy
DATE:
AIM:
To implement Scipy using written modules and Python Standard Libraries.
ALGORITHM:
STEP2: using special function calculate exponential, sin and cos values
PROGRAM:
from scipy import special
a = special.exp10(3)
print(a)
b = special.exp2(3)
print(b)
c = special.sindg(90)
print(c)
d = special.cosdg(45)
print(d)
OUTPUT:
1000.0
8.0
1.0
0.707106781187
RESULT:
Thus implemented Scipy using written modules and Python Standard Libraries was written and executed
successfully.