Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default value for multiple inputs from one line in python

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.

like image 375
808Blues Avatar asked Dec 13 '25 21:12

808Blues


1 Answers

# 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
like image 80
Kate Melnykova Avatar answered Dec 16 '25 11:12

Kate Melnykova



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!