Jan-20-2024, 08:26 PM
Hello, I am Arlind Sherifi. I have just started to learn Python and I have written this code:
import numpy as np perihelion = 70 velocity_perihelion = 80 def velocity_aphelion(perihelion, velocity_perihelion): star_mass = 1.9891e30 G = 6.6738e-11 second_term_1 = (2 * G * star_mass) / (velocity_perihelion) second_term_2 = -4 * ( velocity_perihelion**2 - ((2 * G * star_mass) / (perihelion)) ) v2 = (second_term_1 - np.sqrt(second_term_1**2 - second_term_2)) / 2 return v2 print(velocity_aphelion(perihelion, velocity_perihelion)) def aphelion(perihelion, velocity_perihelion, velocity_aphelion): L2 = (perihelion * velocity_perihelion) / velocity_aphelion return L2 print(aphelion(perihelion, velocity_perihelion, velocity_aphelion)) def Semimajor_axis(perihelion, aphelion): a = (1 / 2) * (perihelion + aphelion) return a def Semiminor_axis(perihelion, aphelion): b = np.sqrt(abs(perihelion * aphelion)) return b def Orbital_period(s_major, s_minor, perihelion, velocity_perihelion): T = (2 * np.pi * s_major * s_minor) / (perihelion * velocity_perihelion) return T def Orbital_eccentricity(perihelion, aphelion): e = (aphelion - perihelion) / (aphelion + perihelion) return e def Planetary_orbits(perihelion, velocity_perihelion): v2 = float(velocity_aphelion(perihelion, velocity_perihelion)) L2 = float(aphelion(perihelion, velocity_perihelion, v2)) s_major = float(Semimajor_axis(perihelion, L2)) s_minor = float(Semiminor_axis(perihelion, L2)) period = float(Orbital_period(s_major, s_minor, perihelion, velocity_perihelion)) eccentricity = float(Orbital_eccentricity(perihelion, L2)) return Planetary_orbits print( "aphelion: %f \n velocity at aphelion: %f \n orbital period: %f \\n eccentricity: %f." % (L2, v2, T, e) )This is the traceback File ~\exercise2.6.py:21 in aphelion
Error:L2=(perihelion*velocity_perihelion)/velocity_aphelion
TypeError: unsupported operand type(s) for /: 'int' and 'function'
Any way how to correct the code, please?