PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'''
Please read this to understand this code
⚠️⚠️⚠️
The twin paradox is a thought experiment in special relativity where one twin stays on Earth while the other travels in a high-speed rocket. Due to time dilation, the traveling twin experiences time passing slower relative to the twin on Earth. When they reunite, the traveling twin has aged less than the twin who stayed on Earth, despite both experiencing time normally from their own perspective.
To use this code first enter time in seconds and velocity in km/s
'''
import matplotlib.pyplot as plt
import numpy as np
import scipy.constants as const
import math
speed_of_light = const.speed_of_light
def time_dilation(del_t, v):
if v >= speed_of_light:
raise ValueError("Velocity must be less than the speed of light")
return del_t / math.sqrt(1 - (v ** 2 / speed_of_light ** 2))
time = float(input("Enter the amount of time(seconds) : "))
velocity = float(input("Enter the speed(km/s) : ")) * 1000
try:
dilated_time = time_dilation(time, velocity)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run