Stewart,
Did you try Google Bard with Gemini?
Hesham
On Wed, Dec 20, 2023, 7:07 AM Stewart Bryant <stewart.bryant@xxxxxxxxx> wrote:
I am building a small program and thought I would ask CharGPT to build theFramework. I asked it the following question as part of asking alarger question about some code I wanted it to write:write python3 code to read two parameters from the command line. The first is IP Address the second is Port. If the command line is not properly formatted print an error with the correct format. Now construct an http URL using the IP address and the port with trailing /. store the URL in string global variable RelayURL Print RelayURLI gotif len(sys.argv) != 3:
print("Error: Incorrect number of arguments.")
print("Usage: python script.py <IP Address> <Port>")
sys.exit(1)
ip_address = sys.argv[1]
port = sys.argv[2]
# Check if the IP Address and Port are properly formatted
try:
# Check if IP Address is valid
parts = ip_address.split('.')
if len(parts) != 4 or not all(0 <= int(part) < 256 for part in parts):
raise ValueError("Invalid IP Address format")
# Check if Port is a valid integer
if not (0 < int(port) < 65536):
raise ValueError("Invalid Port number”)
I must say that I was impressed with the quality of the checking it automatically generated but perhaps disappointed that it assumed IP Address == IPv4. As it turns out I am am using IPv4 but it was a bit presumptuous to assume that :)
- Stewart