Tamilar marabu

Download as pdf or txt
Download as pdf or txt
You are on page 1of 68

EX.

NO:1a
Electricity Billing
DATE:

AIM:

To develop a flowchart for electricity billing.

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:

READ Previous unit,Current Unit


CALCULATE Used Unit = Current Unit – Previous Unit
ElectricityBill=Used Unit x 2
PRINT ElectricityBill
FLOWCHART:

RESULT:
Thus, the flowchart for the electricity billing is developed.
EX. NO:1b.
Retail Shop Billing
DATE:

AIM:

To develop a flowchart for the retail shop billing.

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:

IF more products available THEN


READ bar code
DISPLAY Product name, amount
ELSE
CALCULATE Total Cost
PRINT Total Cost
ENDIF
FLOWCHART:

RESULT:
Thus, the flowchart for retail shop billing is developed.
EX. NO:1c.
Sin Series
DATE:

AIM:

To develop a flowchart for the Sine Series.

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:

To develop a flowchart for finding the weight of a motor bike.

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:

To develop a flowchart for finding weight of a steel bar.

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:

READ diameter, length


IF length in meter, THEN
Weight=diameter*diameter*length/162
ELSE
Weight=diameter*diameter*length/533
ENDIF
PRINT Weight
FLOWCHART:

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:

To develop a flowchart to compute electrical current in three phase AC circuit.

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:

READ voltage, resistance, current and power factor


COMPUTE Electric Current = 3 x voltage x resistance x current x power factor
PRINT Electric Current
FLOWCHART:

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

DATE: Distance between two points

AIM:
To write a Python Program to find the distance between two points.

ALGORITHM:

STEP1: Start the program


STEP2: Import math library
STEP 3: Take a two points as an input from an user.
STEP 4: Calculate the difference between the corresponding X-coordinates i.e.:X2 - X1 and Y coordinates
i.e.:Y2 - Y1of two points.
STEP 5: Apply the formula derived from Pythagorean Theorem
i.e.: sqrt ((X2 - X1) ^2 + (Y2 - Y1) ^2)
STEP 6 : End the program

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

To write a python program to print number series.

ALGORITHM

STEP1: Start the program

STEP2: Initialize the values of a and b

STEP3: Read the number of terms in the sequence; n

STEP4: Print value of a, b

STEP5: add the values of a, b and store in c

STEP6: Print the values of a, b and assign value of b, c into a, b

STEP7: Repeat the step5 & 6 for n-2 times.

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:

To write a python program to print number pattern.

ALGORITHM:

STEP1: Start

STEP2: Range (10) –Range function takes values from 0 to 9

STEP3: str (i) prints string version of i .(i.e i value)

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.

DATE: Area of shape

AIM:
To write a Python Program to find area of shape using functions.

ALGORITHM:

STEP1: Start the program

STEP2: Define a function name area calculator ()

STEP3: Assign area and Pie value

STEP4: Enter the shape you want to calculate

STEP5: print the area of the shape

STEP6: If shape is not found, print select a valid shape

STEP7: End the program

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:

To write a Python Program to reverse a string.

ALGORITHM:

STEP1:Start the program

STEP2:Define a function name myfunction ()

STEP3: Enter text to reverse

STEP4: Reverse the string using slice statement [::-1]

STEP5: Print the reversed string

STEP6: End the program

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:

To write a Python Program to find palindrome for the given string.

ALGORITHM:

STEP1: Start the program

STEP2: Get the string from the user

STEP3: Check given string is equal to slice statement

STEP4: Print string is palindrome or else not palindrome

STEP5: Stop the program

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:

STEP1: Start the program

STEP2: Assign the sentence to the variable

STEP3: Get the character from the user

STEP4: count the character using count ()

STEP5: print the number of occurrences of character

STEP6: Stop the program

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:

To write a Python Program to replace the character.

ALGORITHM:

STEP1: Start the program

STEP2: Get a string from the user

STEP3: Get a replace character from the user and replace the character using replace ()

STEP4: print the string

STEP5: Stop the program

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:

STEP1: Start the program

STE2: Import numpy library

STEP3: create alias for numpy

STEP4: create an array of list

STEP5: Print the array

STEP6: print the shape of array

STEP7: Stop the program

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:

To implement pandas using written modules and Python Standard Libraries

ALGORITHM:

STEP1: Start the program

STEP2: import pandas library

STEP3: create alias for pandas

STEP4: create a simple pandas series from a list

STEP5: store the series in variable

STEP6: print the series using variable

STEP7: Stop the program

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:

To implement matplotlib using written modules and Python Standard Libraries

ALGORITHM:

STEP1: Install Matplotlib

STEP2: Import pyplot and create alias for it.

STEP3: Define the x-axis and corresponding y-axis values as lists.

STEP4: Plot and name them using plt.xlabel () and plt.ylabel () functions

STEP5: Give a title to your plot using .title () function.

STEP6: Finally, to view your plot using show () function.

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:

STEP1: Install Scipy library and import special function

STEP2: using special function calculate exponential, sin and cos values

STEP3: Print the 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.

You might also like