I'm trying to get specifications three necessary inputs and a fourth optional one from one input in Python.
a, b, c, d = input("Please enter the number of the figure you would like and the x y coordinated in that order and a colour if you choose.").split()
I want d to be optional with a set default value but I'm really struggling with it.
# get input
inp = input("Please enter the number of the figure you would like and the x y coordinated in that order and a colour if you choose.").split()
# check how many parameters are passed
if len(input) == 3:
# value for d is not passed
a, b, c = inp
d = default_value
else:
# value for d is passed
a, b, c, d = inp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With