└── fly /fly: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def calculate_surface_area(radius): 4 | """ 5 | Calculate the surface area of a planet given its radius. 6 | 7 | Parameters: 8 | radius (float): The radius of the planet in kilometers. 9 | 10 | Returns: 11 | float: The surface area of the planet in square kilometers. 12 | """ 13 | return 4 * math.pi * (radius ** 2) 14 | 15 | def main(): 16 | print("Planet Surface Area Calculator") 17 | planets = [] 18 | 19 | while True: 20 | try: 21 | # Get user input for the planet's name and radius 22 | planet_name = input("Enter the name of the planet (or type 'done' to finish): ") 23 | if planet_name.lower() == 'done': 24 | break 25 | 26 | radius = float(input(f"Enter the radius of {planet_name} in kilometers: ")) 27 | 28 | if radius <= 0: 29 | raise ValueError("The radius must be a positive number.") 30 | 31 | # Calculate the surface area 32 | surface_area = calculate_surface_area(radius) 33 | 34 | # Store the result 35 | planets.append((planet_name, radius, surface_area)) 36 | 37 | except ValueError as ve: 38 | print(f"Error: {ve}") 39 | 40 | # Output the results for all planets 41 | print("\nSurface Areas of Planets:") 42 | for planet in planets: 43 | print(f"The surface area of {planet[0]} with radius {planet[1]} km is {planet[2]:.2f} square kilometers.") 44 | 45 | if name == "__main__": 46 | main() 47 | --------------------------------------------------------------------------------