EXPERIMENT No. 1
Python Lab Practical Record · Python programming laboratory
Read with diagrams, search and self-test
1A. Find the maximum of three forces (decision making)
Aim
To write an algorithm, draw a flowchart and write a Python program to find the maximum of three forces A, B and C.
Algorithm
Step 1: Start.
Step 2: Read three forces A, B and C.
Step 3: If A ≥ B and A ≥ C, print A as the maximum.
Step 4: Else, if B ≥ A and B ≥ C, print B as the maximum.
Step 5: Otherwise, print C as the maximum.
Step 6: Stop.
Flowchart
Program (max_of_three_forces.py)
# Exp 1A: Maximum of three forces (decision making)
A = float(input("Enter force A (N): "))
B = float(input("Enter force B (N): "))
C = float(input("Enter force C (N): "))
if A >= B and A >= C:
print("Maximum force =", A, "N")
elif B >= A and B >= C:
print("Maximum force =", B, "N")
else:
print("Maximum force =", C, "N")Output
Enter force A (N): 30 Enter force B (N): 45 Enter force C (N): 25 Maximum force = 45.0 N
Result
The maximum of the three forces was found using if–elif–else decision making.
1B. Convert Fahrenheit to Centigrade
Aim
To write an algorithm, draw a flowchart and write a Python program to convert a temperature from Fahrenheit to Centigrade.
Algorithm
Step 1: Start.
Step 2: Read the temperature F in Fahrenheit.
Step 3: Calculate C = (F − 32) × 5 / 9.
Step 4: Display C.
Step 5: Stop.
Flowchart
Program (fahrenheit_to_centigrade.py)
# Exp 1B: Convert Fahrenheit to Centigrade
F = float(input("Enter temperature in Fahrenheit: "))
C = (F - 32) * 5 / 9
print("Temperature in Centigrade =", round(C, 2))Output
Enter temperature in Fahrenheit: 98.6 Temperature in Centigrade = 37.0
Result
The temperature in Fahrenheit was converted to Centigrade using C = (F − 32) × 5/9.
1C. Generate the multiplication table of 5 (control loop)
Aim
To write an algorithm, draw a flowchart and write a Python program to generate the multiplication table of 5 using a loop.
Algorithm
Step 1: Start.
Step 2: Initialise i = 1.
Step 3: If i ≤ 10, go to Step 4; otherwise go to Step 6.
Step 4: Print 5 × i = 5*i.
Step 5: Increment i = i + 1 and go to Step 3.
Step 6: Stop.
Flowchart
Program (multiplication_table_5.py)
# Exp 1C: Multiplication table of 5 (control loop)
i = 1
while i <= 10:
print("5 x", i, "=", 5 * i)
i = i + 1Output
5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50
Result
The multiplication table of 5 was generated using a while loop.
1D. Efficiency of a simple machine
Aim
To write an algorithm, draw a flowchart and write a Python program to find the efficiency of a simple machine.
Algorithm
Step 1: Start.
Step 2: Read the input x and the output y.
Step 3: Calculate Efficiency = (y / x) × 100.
Step 4: Display the efficiency.
Step 5: Stop.
Flowchart
Program (efficiency_simple_machine.py)
# Exp 1D: Efficiency of a simple machine
x = float(input("Enter input (work/power) x: "))
y = float(input("Enter output (work/power) y: "))
efficiency = (y / x) * 100
print("Efficiency =", round(efficiency, 2), "%")Output
Enter input (work/power) x: 500 Enter output (work/power) y: 400 Efficiency = 80.0 %
Result
The efficiency of the simple machine was calculated using Efficiency = (output / input) × 100.