Write Python app. It takes CLI args. Calculate the area of a square (two numbers) or…
- User
Write Python app. It takes CLI args. Calculate the area of a square (two numbers) or cube (three nums).
- Assistant
Sure! Here's a Python app that calculates the area of a square or the volume of a cube based on the command-line arguments provided:
import sys def calculate_square_area(side): return side ** 2 def calculate_cube_volume(side): return side ** 3 def main(): args = sys.argv[1:] if len(args) == 2: # Square area calculation try: side = float(args[0]) area = calculate_square_area(side) print("Area of the square:", area) except ValueError: print("Invalid input. Please provide two numbers.") elif len(args) == 3: # Cube volume calculation try: side = float(args[0]) volume = calculate_cube_volume(side) print("Volume of the cube:", volume) except ValueError: print("Invalid input. Please provide three numbers.") else: print("Invalid number of arguments. Please provide two numbers for square or three numbers for cube.") if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.