Last active 1730124976

get kinetic energy for any object you know the speed and weight

mathieu's Avatar mathieu revised this gist 1730124976. Go to revision

1 file changed, 0 insertions, 0 deletions

kynetic_energy.py renamed to kinetic_energy.py

File renamed without changes

mathieu's Avatar mathieu revised this gist 1730124947. Go to revision

1 file changed, 40 insertions

kynetic_energy.py(file created)

@@ -0,0 +1,40 @@
1 + #!/usr/bin/env python3
2 +
3 + import argparse
4 +
5 + # get kinetic energy for any object you know the speed and weight
6 + # To use, just run python3 kinetic_energy.py --speed 30 --weight 1500
7 + # speed is in Km/h, weight in Kg
8 +
9 +
10 + def calculate_energy(weight, velocity):
11 + # Convert weight from kg to Newtons (1 kg = 9.81 N)
12 + mass = weight * 9.81
13 +
14 + # Calculate kinetic energy (in Joules)
15 + kinetic_energy = 0.5 * mass * (velocity**2)
16 +
17 + return kinetic_energy
18 +
19 +
20 + def convert_kmh_to_ms(kmh):
21 + return kmh * (1000 / 3600)
22 +
23 +
24 + if __name__ == "__main__":
25 + parser = argparse.ArgumentParser(
26 + description="Calculate kinetic energy of a moving vehicle"
27 + )
28 + parser.add_argument(
29 + "-s", type=float, required=True, help="Velocity in kilometers per hour"
30 + )
31 + parser.add_argument("-w", type=float, required=True, help="Weight in kilograms")
32 + args = parser.parse_args()
33 +
34 + velocity_km = args.s
35 + velocity_ms = convert_kmh_to_ms(velocity_km)
36 + weight = args.w
37 +
38 + energy = calculate_energy(weight, velocity_ms)
39 +
40 + print(f"Kinetic Energy: {energy:.2f} J")
Newer Older