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
Here's a simple Python application that takes command line arguments to calculate the area of a square or the volume of a cube.
import sys def main(): if len(sys.argv) == 5: side = float(sys.argv[1]) height = float(sys.argv[3]) print(f"Cube Volume: {calculate_volume(side, height)}") elif len(sys.argv) == 3: side = float(sys.argv[1]) print(f"Square Area: {calculate_area(side)}") else: print("Invalid number of arguments. Please provide either 2 or 3 numbers.") def calculate_area(side): return side * side def calculate_volume(side, height): return side * side * height if __name__ == "__main__": main()To use this application, save it as
area_and_volume.pyand run it with the appropriate command line arguments.For calculating the area of a square:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.