Achieve The User Input For Default Parameter Functionality In Python
Here is a C++ code I wrote to default to user input when arguments are not provided explicitly. I have been learning Python-3.7 for the past week and am trying to achieve a similar
Solution 1:
int(input())
is executed when the function is defined. What you should do is use a default like None
, then do number = int(input())
if needed:
def foo(number=None):
if number is None:
number = int(input())
print(number)
Post a Comment for "Achieve The User Input For Default Parameter Functionality In Python"