Голосование за лучший ответ
♡$ⴎG@r₱u₷sყ♡
Искусственный Интеллект
(157223)
6 месяцев назад
Метод `__init__` должен иметь двойное подчёркивание с обеих сторон. В формуле максимальной высоты вместо `self.initial_velocity ** 2` использовано `self.initial_velocity 2`, что является синтаксической ошибкой. Правильно будет `self.initial_velocity ** 2`.
Дракошикина Заварка
Гуру
(3697)
6 месяцев назад
import math
class BallisticMissile:
def __init__(self, initial_velocity, launch_angle): # Changed 'init' to '__init__'
self.initial_velocity = initial_velocity
self.launch_angle = launch_angle
self.gravity = 9.81
self.time_of_flight = 0
self.max_height = 0
self.horizontal_distance = 0
def calculate_flight(self):
time_to_peak = self.initial_velocity * math.sin(math.radians(self.launch_angle)) / self.gravity
self.max_height = (self.initial_velocity ** 2 * (math.sin(math.radians(self.launch_angle)) ** 2)) / (2 * self.gravity) # Fixed missing '**' for power
self.time_of_flight = 2 * time_to_peak
self.horizontal_distance = self.initial_velocity ** 2 * math.sin(math.radians(2 * self.launch_angle)) / self.gravity
def print_results(self):
print("Results of the ballistic missile simulation:")
print(f"Time of flight: {self.time_of_flight:.2f} seconds") # using f-string for formatting
print(f"Maximum height: {self.max_height:.2f} meters")
print(f"Horizontal distance traveled: {self.horizontal_distance:.2f} meters")
# Example usage
missile = BallisticMissile(100, 45) # Example values for velocity and angle
missile.calculate_flight()
missile.print_results()
class BallisticMissile:
def init(self, initial_velocity, launch_angle):
self.initial_velocity = initial_velocity
self.launch_angle = launch_angle
self.gravity = 9.81
self.time_of_flight = 0
self.max_height = 0
self.horizontal_distance = 0
def calculate_flight(self):
time_to_peak = self.initial_velocity * math.sin(math.radians(self.launch_angle)) / self.gravity
self.max_height = (self.initial_velocity 2 * (math.sin(math.radians(self.launch_angle)) 2)) / (2 * self.gravity)
self.time_of_flight = 2 * time_to_peak
self.horizontal_distance = self.initial_velocity ** 2 * math.sin(math.radians(2 * self.launch_angle)) / self.gravity
def print_results(self):
print("Results of the ballistic missile simulation:")
print("Time of flight: {:.2f} seconds".format(self.time_of_flight))
print("Maximum height: {:.2f} meters".format(self.max_height))
print("Horizontal distance traveled: {:.2f} meters".format(self.horizontal_distance))
высосите из пальца