0% found this document useful (0 votes)
10 views

Notes to develop flow charts ++

Notes to develop flow chart + simple statements + conditional and iterative loops in Python

Uploaded by

mosesshaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Notes to develop flow charts ++

Notes to develop flow chart + simple statements + conditional and iterative loops in Python

Uploaded by

mosesshaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

EX. NO.

: 1a WEIGHT OF A STEEL BAR

AIM:

To develop an algorithm and flowchart for calculating the Weight of a Steel Bar.

ALGORITHM:

Step 1: Start

Step 2: Get the diameter of the steel bar (D) in millimeters.

Step 3: Get the length of the steel bar (L) in meters.

Step 4: Calculate the weight using the formula:

W=D^2×L/162

Step 5: Display the weight (W) of the steel bar in kilograms.

Step 6: Stop
FLOWCHART:
OUTPUT:

Expected Output Actual Output

Test Case Length (meters) Diameter (mm) Weight (kg) Weight (kg)

1 10 5 1.54

2 20 8 7.90

3 15 10 9.26

4 5 12 4.44

RESULT:

Thus, the algorithm and flowchart for calculating the Weight of a Steel Bar were designed
and verified successfully.
EX. NO.: 1b COMPUTE ELECTRICAL CURRENT IN THREE PHASE AC CIRCUIT

AIM:

To develop an algorithm and flowchart for computing Electrical Current in 3 Phase AC


Circuit.

ALGORITHM:

Step 1: Start

Step 2: Get the power (P) in watts.

Step 3: Get the voltage (V) in volts.

Step 4: Get the power factor (pf).

Step 5: Calculate the current (I) using the formula:


𝑃
𝐼=
√3 ∗ 𝑉 ∗ 𝑝𝑓
Step 6: Get the number of hours used per day.

Step 7: Get the rate per kilowatt-hour (kWh).

Step 8: Calculate the total energy consumed:

Energy (kWh) = 𝑃 × hours per day / 1000

Step 9: Calculate the bill by multiplying energy consumption by the rate:

Bill = Energy (kWh) × Rate

Step 10: Display the current (I) in amperes.

Step 11: Display the bill amount.

Step 12: Stop


FLOWCHART:
OUTPUT:

EXPECTED ACTUAL OUTPUT


OUTPUT

Rate Current Bill


Power Voltage Power Hours per Current (I) (₹)
Test (P) (V) Factor per kWh (I) Bill (amperes)
Case (watts) (volts) (pf) Day (₹) (amperes) (₹)

1 1500 230 0.8 5 5 4.69 37.5

2 2000 240 0.9 8 6 5.35 96

3 1000 220 0.85 10 4 3.06 40

4 500 210 0.75 6 5.5 1.83 16.5

RESULT:

Thus, the algorithm and flowchart for computing Electrical Current in 3 Phase AC Circuit
were designed and verified successfully.
EX. NO.: 1c WEIGHT OF A MOTORBIKE

AIM:

To develop an algorithm and flowchart for finding the Weight of a Motorbike.

ALGORITHM:

Step 1: Start

Step 2: Get bike_type in a string

Step 3: If bike_type = "Chopper", print "A Chopper weighs about 315 kg."

Step 4: If bike_type = "Sport bike", print "A Sport bike weighs about 180 kg."

Step 5: If bike_type = "Scooter", print "A Scooter weighs about 115 kg."

Step 6: Otherwise, print "Sorry, I don't have information on that bike type."

Step 7: Stop
FLOWCHART:
OUTPUT:

Input Expected Output Actual Output

Chopper Chopper weighs about 315 kg

Sport bike Sport bike weighs about 180 kg

Scooter Scooter weighs about 115 kg

Sorry, I don’t have the information on


E-Bike E-Bike

RESULT:

Thus, the algorithm and flowchart for finding the Weight of a Motorbike were designed and
verified successfully.
EX. NO.: 1d RETAIL SHOP BILLING

AIM:

To develop an algorithm and flowchart for Retail Shop Billing problem.

ALGORITHM:

Step 1: Start
Step 2: Get the product name PROD1.
Step 3: Get the quantity Q1 of PROD1.
Step 4: Get the price P1 of product PROD1.
Step 5: Get the product name PROD2.
Step 6: Get the quantity Q2 of product PROD2.
Step 7: Get the price P2 of product PROD2.
Step 8: Get the product name PROD3.
Step 9: Get the quantity Q3 of product PROD3.
Step 10: Get the price P3 of product PROD3.
Step 11: Calculate the total price of all products:
TOTALPRICE = (Q1×P1) + (Q2*P2) + (Q3*P3)
Step 12: If TOTALPRICE > 1000, then:
Calculate the discount as 10% of TOTALPRICE:
DISCOUNT=TOTALPRICE× 10/100
Step 13: Else, if TOTALPRICE <= 1000, then:
Calculate the discount as 5% of TOTALPRICE:
DISCOUNT=TOTALPRICE× 5/ 100
Step 14: BILL=TOTALPRICE−DISCOUNT
Step 15: Display the value of the final bill (BILL).
Step 16: Stop.
FLOWCHART:
OUTPUT:

Test Case Input Expected Output Actual Output

PROD1 = A, P1 = 200, Q1 =
2,
1 PROD2 = B, P2 = 500, Q2 = 903
1,
PROD3 = C, P3 = 50, Q3 = 1
PROD1 = PEN, P1 = 50, Q1 =
2,
PROD2 = PENCIL, P2 = 25,
2 3240
Q2 = 100,
PROD3 = PAPER, P3 = 10,
Q3 = 100
PROD1 = LAPTOP, P1 =
50000, Q1 = 1,
PROD2 = MOUSE, P2 =
3 48600
1000, Q2 = 2,
PROD3 = KEYBOARD, P3 =
2000, Q3 = 1
PROD1 = RICE, P1 = 40, Q1 =
10,
PROD2 = WHEAT, P2 = 30,
4 990
Q2 = 15,
PROD3 = SUGAR, P3 = 50,
Q3 = 5

RESULT:

Thus, the solution for Retail shop bill generation problem is arrived, an algorithm and
flowchart were designed and verified successfully.
EX.NO.: 1e ELECTRICITY BILL

AIM:

To develop an algorithm and flowchart for calculating electricity bill problem.

ALGORITHM:

Step 1: Start.

Step 2: Get the value of number of unit's power consumed from the user and store it in "Unit".

Step 3: Check the value of "Unit". If it is less than or equals to 100 then go to Step 3.1.

Otherwise go to Step 4.

Step 3.1: Perform the below computation

Fixed_Charge = 0

Energy_Charge = 0

Amount_Payable = Fixed_Charge + Energy_Charge

Step 3.2: Display the "Amount_Payable" and then go to Step 7

Step 4: If the value of "Unit" is lesser than or equals to 200 then go to Step 4.1.

Otherwise go to Step 5.

Step 4.1: Perform the below computation

Fixed_Charge = 20

Energy_Charge = (Unit-100)*1.5

Amount_Payable = Fixed_Charge + Energy_Charge

Step 4.2: Display the "Amount_Payable" and then go to Step 7

Step 5: If the value of "Unit" is lesser than or equals to 500 then go to Step 5.1.

Otherwise go to Step 6.

Step 5.1: Perform the below computation

Fixed_Charge = 30

Energy_Charge = (Unit-200)*3+ (100*2)

Amount_Payable = Fixed_Charge + Energy_Charge

Step 5.2: Display the "Amount_Payable" and then go to Step 7

Step 6: For the remaining values of "Unit" perform the below calculation.

Fixed_Charge=30
Energy_Charge= (Unit-500)*6.6 + (300*4.6) + (100*3.5)

Amount_Payable = Fixed_Charge + Energy_Charge

Step 7: Display the value of "Amount_Payable" to user.

Step 8: Stop.
FLOWCHART:
OUTPUT:

Expected Output Actual Output


Test Case Input U
(Amount Payable) (Amount Payable)

1 50 0

2 150 95

3 250 380

4 600 2420

RESULT:

Thus, the algorithm and flowchart for calculating electricity bill were designed and verified
successfully.
EX. NO.: 1f SINE SERIES

AIM:

To develop an algorithm and flowchart for Sine Series.

ALGORITHM:

Step 1: Start

Step 2: Get the value of angle (in degrees).

Step 3: Convert the angle from degrees to radians using the formula:

Step 4: 𝑥 = 𝑎𝑛𝑔𝑙𝑒 × pi / 180

Step 5: Initialize term = x and sum = x.

Step 6: Get the value of n (the number of terms to compute).

Step 7: Initialize i = 1.

Step 8: While i < n:

Term = −term * x* x / ((2*i)*(2*i+1))

sum=sum+term

Increment i by 1.

Step 9: Display the final value of sum.

Step 10: Stop.


FLOWCHART:
OUTPUT:

Test Angle Number of Expected Output (Sum of Actual Output


Case (degrees) Terms (n) Sine Series) (Approx) (Sum of Sine Series) (Approx)

1 30 4 0.4999

2 45 3 0.7071

3 -45 6 -0.7071

4 60 7 0.8660

RESULT:

Thus, the algorithm and flowchart for the Sine Series were designed and verified successfully.
EX. NO.: 2a EXCHANGE THE VALUES OF TWO VARIABLES

AIM:

To write a python program to exchange the values of two variables.

ALGORITHM:

Step 1: Start
Step 2: Get the values of a and b
Step 3: temp=a
Step 4: a=b
Step 5: b=temp
Step 6: Display a and b
Step 7: Stop

FLOWCHART:
PROGRAM:

Swapping of Two Numbers using temporary variables

print("Swapping using temporary variable")


a = int(input("a = "))
b = int(input("b = "))
print("Before Swapping")
print("a = ", a)
print("b = ", b)
temp = a
a=b
b = temp
print("After Swapping")
print("a = ", a)
print ("b = ", b)

OUTPUT:

Actual Output
Expected Output Expected Output
Test Case Input Values Before Swapping After Swapping After Swapping

1 a = 5, b = 10 a = 5, b = 10 a = 10, b = 5

2 a = -3, b = 7 a = -3, b = 7 a = 7, b = -3

3 a = 0, b = 1 a = 0, b = 1 a = 1, b = 0

Result:

Thus, the python program to swap two input numbers was implemented and verified
successfully.
EX. NO.: 2b SUM OF FIRST N NATURAL NUMBERS

AIM:

To write a python program to calculate the sum of first n natural numbers.

ALGORITHM:

Step 1: Start
Step 2: Get the value of n
Step 3: Initialize the variables as follows:
i=1
sum = 0
Step 4: If i<= n then go to step 5 otherwise, go to step 7
Step 5: Sum=sum+i
Step 6: i = i +1
Step 7: Go to step 4
Step 8: Display the value of sum
Step 9: Stop

FLOWCHART:
PROGRAM:

n = int(input("Enter a number: "))


sum = 0
i=1
while(i<=n):
sum=sum+i
i=i+1
print("The sum of the first", n, "natural numbers is", sum)

OUTPUT:

Test Case Input Expected Output Actual Output


Enter a number: The sum of the first 5
1
5 natural numbers is 15
Enter a number: The sum of the first 10
2
10 natural numbers is 55
Enter a number: The sum of the first 100
3
100 natural numbers is 5050

Result:

Thus, the python program to calculate the sum of first n natural numbers was implemented
and verified successfully.
EX. NO.: 2C DISTANCE BETWEEN TWO POINTS

AIM:

To write a python program for calculating distance between two points.

ALGORITHM:

Step 1: Start
Step 2: Get the values of x1, y1, x2 and y2.
Step 3: Calculate the distance between two points using the following expression
distance = (𝑥2 − 𝑥1) + (𝑦2 − 𝑦1)
Step 4: Display the value of distance
Step 5: Stop

FLOWCHART:
PROGRAM:

import math
xl=int(input("enter x1"))
yl=int(input("enter y1"))
x2=int(input("enter x2"))
y2=int(input("enter y2"))
distance = math.sqrt(((x2-x1)**2)+((y2- y1)**2))
print(distance)

OUTPUT:

Input (xl, yl,


Test Case Expected Output Actual Output
x2, y2)
x1 = 1,
y1 = 1,
1 5.0
x2 = 4,
y2 = 5
x1 = 2,
y1 = 3,
2 0.0
x2 = 2,
y2 = 3
x1 = -1,
y1 = -1,
3 2.8284271247461903
x2 = 1,
y2 = 1

Result:

Thus, the python program to calculate the distance between two points was implemented
and verified successfully.
EX. NO.: 3a NUMBER SERIES

AlM:

To write a python program to find sum of series

1+𝑿𝟏 +𝑿𝟐 +𝑿𝟑 +….+𝑿𝒏

ALGORITHM:

Step 1: Start
Step 2: Get the values of x and n.
Step 3: Initialize s = 0, i = 0
Step 4: If i<=n, then go to step 5. Otherwise go to step 8
Step 5: s=s+x**i
Step 6: i = i+1
Step 7: Go to step 4.
Step 8: Display the value of s.
Step 9: Stop

PROGRAM:

x=int (input ("enter the value of x"))


n=int (input ("enter the value of n"))
s=0
i=0
while (i<=n) :
s=s+x**i
i=i+1
print ("sum of series",s)

OUTPUT:

Test Case Input Values Expected Output Actual Output

1 x = 2, n = 3 15

2 x = 1, n = 5 6

3 x = 3, n = 2 13

RESULT:

Thus, the python program to find the sum of series was implemented and verified
successfully.
EX. NO.: 3b NUMBER PATTERNS

AIM:

To write a python program to print number pattern as shown below

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
ALGORITHM:

Step 1: Start
Step 2: Get the number of rows in pattern, n.
Step 3: Create a nested loop as follows:
for i = 0 to n-1
for j = 0 to i+1
display j+1
Step 4: Stop

PROGRAM:

n=int (input ("enter number of rows needed: "))


for i in range(n):
for j in range(i+1):
print (j+1,end=" ")
print()

OUTPUT:

Test Case Input Value Expected Output Actual Output

1
1 n=3 1 2
1 2 3
1
1 2
2 n=5 1 2 3
1 2 3 4
1 2 3 4 5

RESULT:

Thus, the python program to find the to print number patterns was implemented and
verified successfully.
EX. NO.: 3c PYRAMID PATTERN

AIM:

To write a python program to display pyramid pattern as show below

*
* *
* * *
* * * *
* * * * *
ALGORITHM:
Step 1: Start
Step 2: Get the number of rows, num
Step 3: Create a nested loop as follows:
for i = 0 to num-1
for j = 0 to num-i-1
display “ “
for j = 0 to i+1
display “*”
Step 4: Stop

PROGRAM:
num=int (input ("Enter the number of rows:"))
for i in range(0,num) :
for j in range(0,num-i-1):
print (end=" ")
for j in range(0,i+1):
print ("*",end=" ")
print ()

OUTPUT:
Input Value
Test Case Expected Output Actual Output
Enter the number of rows:
*
1 3 * *
* * *
*
* *
* * *
2 5
* * * *
* * * * *

RESULT:
Thus, the python program to find the to print pyramid pattern was implemented and
verified successfully.

You might also like