So my goal is to enter 80x40
and it enters it in size
and return with the format (80, 40)
.
But if I write 80xdf
, it will give an error message and use the default value,
then I also want it to give an error when you write one of the arguments < 1
.
Also if it's formatted wrong, it should give out an error message.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('width', type=int, help='width of the world')
parser.add_argument('x', type=int, help='x')
parser.add_argument('height', type=int, help='height of the world')
args = parser.parse_args()
if args.width and args.height < 1:
print("Both width and height needs to have positive values above zero.")
print("Using default world size: 80x40")
size = tuple(80, 40)
elif args.format(args.width, args.x, args.height):
size = tuple("{},{}".format(args.width, args.height))
else:
print("World size should contain width and height, separated by ‘x’. Ex:'80x40'")
print("Using default world size: 80x40")
size = tuple(80, 40)
Error I face when I enter -ws 80x40 -g 0:
usage: main.py [-h] width x height
main.py: error: argument width: invalid int value: '80x40'