0% found this document useful (0 votes)
15 views2 pages

Python Basics for Mechanical Engineering

The document presents a Python lab experiment aimed at introducing basic syntax, variables, and data types through a simple program. It demonstrates mechanical engineering calculations involving material properties like density and Young's modulus, as well as stress analysis. The program outputs relevant information including material characteristics and results of calculations for mass, stress, and strain.
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)
15 views2 pages

Python Basics for Mechanical Engineering

The document presents a Python lab experiment aimed at introducing basic syntax, variables, and data types through a simple program. It demonstrates mechanical engineering calculations involving material properties like density and Young's modulus, as well as stress analysis. The program outputs relevant information including material characteristics and results of calculations for mass, stress, and strain.
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

B.

Tech-7th Sem Python - Lab

EXPERIMENT NO. 1

Aim: Write and execute a simple Python program & Basic syntax, variables, and data types.

Code:
def exp_1_introduction():
"""Introduction to Python with basic mechanical engineering calculations"""
print("="*50)
print("PROGRAM 1: INTRODUCTION TO PYTHON")
print("="*50)

# Basic variables and data types


material_name = "Steel" # String
density = 3568 # Integer (kg/m³)
youngs_modulus = 200.0e9 # Float (Pa)
is_ductile = True # Boolean

# Basic calculations
volume = 0.001 # m³
mass = density * volume

print(f"Material: {material_name}")
print(f"Density: {density} kg/m³")
print(f"Young's Modulus: {youngs_modulus:.2e} Pa")
print(f"Is Ductile: {is_ductile}")
print(f"Volume: {volume} m³")
print(f"Mass: {mass} kg")

# Basic arithmetic operations


force = 1000 # N
area = 0.01 # m²
stress = force / area
strain = stress / youngs_modulus

print(f"\nStress Analysis:")
print(f"Applied Force: {force} N")
print(f"Cross-sectional Area: {area} m²")
print(f"Stress: {stress:.2f} Pa")
print(f"Strain: {strain:.6f}")

# Call the function to execute it

1
[Link]-7th Sem Python - Lab

exp_1_introduction()

OUTPUT:
==================================================
PROGRAM 1: INTRODUCTION TO PYTHON
==================================================
Material: Steel
Density: 3568 kg/m³
Young's Modulus: 2.00e+11 Pa
Is Ductile: True
Volume: 0.001 m³
Mass: 3.568 kg

Stress Analysis:
Applied Force: 1000 N
Cross-sectional Area: 0.01 m²
Stress: 100000.00 Pa
Strain: 0.000000

You might also like