Skip to content

Commit e510928

Browse files
authored
Create special_relativity_calculator.py
1 parent 932ec1f commit e510928

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#This code is made by MRayan Asim
2+
# Function to calculate time dilation
3+
def time_dilation(time, velocity):
4+
gamma = 1 / (1 - (velocity**2 / 299792458**2)) # Lorentz factor
5+
time_dilated = time * gamma
6+
return time_dilated
7+
8+
# Function to calculate length contraction
9+
def length_contraction(length, velocity):
10+
gamma = 1 / (1 - (velocity**2 / 299792458**2)) # Lorentz factor
11+
length_contracted = length / gamma
12+
return length_contracted
13+
14+
# Function to calculate energy using E=mc^2
15+
def energy(mass):
16+
c = 299792458 # Speed of light in m/s
17+
energy = mass * c**2
18+
return energy
19+
20+
if __name__ == "__main__":
21+
# Input values
22+
relative_velocity = float(input("Enter the relative velocity (m/s): "))
23+
proper_time = float(input("Enter the proper time (seconds): "))
24+
proper_length = float(input("Enter the proper length (meters): "))
25+
object_mass = float(input("Enter the mass of the object (kg): "))
26+
27+
# Calculate time dilation, length contraction, and energy
28+
dilated_time = time_dilation(proper_time, relative_velocity)
29+
contracted_length = length_contraction(proper_length, relative_velocity)
30+
object_energy = energy(object_mass)
31+
32+
# Output results without rounding
33+
print(f"Time dilation: {dilated_time:.15f} seconds")
34+
print(f"Length contraction: {contracted_length:.15f} meters")
35+
print(f"Energy (E=mc^2): {object_energy:.15f} joules")

0 commit comments

Comments
 (0)