✦ VidyaVerseOpen interactive version

← Python Lab Practical Record

EXPERIMENT No. 2

Python Lab Practical Record · Python programming laboratory

Read with diagrams, search and self-test

2A. Accept two numbers and perform arithmetic operations

Aim

To write a Python program to accept two numbers and perform arithmetic operations.

Program (arithmetic_operations.py)

# Exp 2A: Accept two numbers and perform arithmetic operations
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Addition =", a + b)
print("Subtraction =", a - b)
print("Multiplication =", a * b)
print("Division =", a / b)
print("Power =", a ** b)

Output

Enter first number: 10
Enter second number: 2
Addition = 12
Subtraction = 8
Multiplication = 20
Division = 5.0
Power = 100

Result

Addition, subtraction, multiplication, division and power of two numbers were obtained.

2B. Calculate age after 5 years

Aim

To write a Python program to calculate a person's age after 5 years.

Program (age_after_5_years.py)

# Exp 2B: Calculate age after 5 years
age = int(input("Enter your age: "))
future_age = age + 5
print("Age after 5 years =", future_age)

Output

Enter your age: 12
Age after 5 years = 17

Result

The age after 5 years was calculated.

2C. Find the area of a rectangle

Aim

To write a Python program to find the area of a rectangle.

Program (area_of_rectangle.py)

# Exp 2C: Area of a rectangle
length = float(input("Enter length: "))
breadth = float(input("Enter breadth: "))
area = length * breadth
print("Area of rectangle =", area)

Output

Enter length: 10
Enter breadth: 5
Area of rectangle = 50.0

Result

The area of the rectangle was calculated as length × breadth.

2D. Output speed and torque of a gear system

Aim

To write a Python program to calculate the output speed and torque of a gear system from user-input values of input speed, input torque and gear ratio, using basic operations.

Formula / Note

Output speed = input speed ÷ gear ratio; Output torque = input torque × gear ratio (power losses neglected).

Program (gear_speed_torque.py)

# Exp 2D: Output speed and torque of a gear system
input_speed = float(input("Enter input speed (rpm): "))
input_torque = float(input("Enter input torque (N-m): "))
gear_ratio = float(input("Enter gear ratio: "))
output_speed = input_speed / gear_ratio
output_torque = input_torque * gear_ratio
print("Output speed =", output_speed, "rpm")
print("Output torque =", output_torque, "N-m")

Output

Enter input speed (rpm): 1000
Enter input torque (N-m): 50
Enter gear ratio: 2
Output speed = 500.0 rpm
Output torque = 100.0 N-m

Result

The output speed and output torque of the gear system were calculated using basic operations.