Traceback (most recent call last): File "<string>", line 23, in <module>TypeError: '>' not supported between instances of 'complex' and 'in

Joined
Dec 1, 2023
Messages
1
Reaction score
0
This is the code and I am getting the following error (program is a free fall calculator):
import math

earth_mass = 5.972e24 # kg
earth_radius = 6371000 # meters
time_step = 0.01
# user values

print(f"Program only works up to 85000 meters")
initial_height = float(input("Enter the initial altitude (meters): "))
print(f"Drag Coefficient values for known shapes are: sphere = 0.47, cube = 1.05, cylinder = 0.82, cone = 0.5, human_spread_eagle = 1.0")
drag_coefficient = float(input("Enter the Drag Coefficient of the object:"
))
mass = float(input("Enter the mass of the object (kg): "))
diameter = float(input("Enter the diameter of the object (meters): "))
initial_velocity = float(input("Enter the initial velocity (m/s): "))
initial_acceleration = float(input("Enter the initial acceleration (m/s^2): "))

# No atmosphere calculation
altitude = initial_height
velocity = initial_velocity
acceleration = initial_acceleration
time = 0.0
while altitude > 0:
gravity = 6.67e-11 * (earth_mass / (earth_radius + altitude)**2)
area = math.pi * (diameter / 2)**2
if 71000 <= altitude <= 85000:
density = 1.225 / (1 + 0.00694 * altitude) ** 0.0171
elif 51000 <= altitude < 71000:
density = 1.225 / (1 + 0.00971 * altitude) ** 0.01222
elif 47000 <= altitude < 51000:
density = 1.225
elif 32000 <= altitude < 47000:
density = 1.225 * (1 - 0.00971 * altitude) ** 0.0122
elif 20000 <= altitude < 32000:
density = 1.225 * (1 - 0.00347 * altitude) ** 0.0171
elif 11000 <= altitude < 20000:
density = 1.225
else:
density = 1.225 * (1 - 0.00002 * altitude) ** 5.26

drag_force = 0.5 * density * velocity**2 * area * drag_coefficient
acceleration = (gravity - drag_force / mass)
velocity += acceleration * time_step
altitude -= velocity * time_step
time += time_step

print(f"Freefall time with atmosphere: {time:.2f} seconds")

# No atmosphere calculation
altitude = initial_height
velocity = initial_velocity
acceleration = initial_acceleration
time = 0.0
while altitude > 0:
gravity = 6.67e-11 * (earth_mass / ((earth_radius + altitude)**2))
acceleration = initial_acceleration + gravity
velocity += acceleration * time_step
altitude -= velocity * time_step
time += time_step
print(f"Freefall time without atmosphere: {time:.2f} seconds")
 
Joined
Sep 21, 2022
Messages
122
Reaction score
15
I'm not a Python programmer, but I'll have a guess.

if altitude=31999 then (1 - 0.00347 * altitude) is negative

** 0.0171 of a negative number is not a real number.

conjecture:
Python is returning a complex number.

complex * float = complex
complex + float = complex

density is now complex

density changes drag_force

drag_force changes acceleration

acceleration changes velocity

velocity is added to altitude, so altitude is now a complex variable

altitude > 0 is now an invalid expression

Just my opinion, I could be wrong.
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top