+ 2
Function arguments
I want to make a function that prints hello world if no argument is provided or the argument if it is provided https://code.sololearn.com/cHtyvT4ky0rt/?ref=app Help.
7 Respuestas
+ 4
Like you provided the default value for parameter option 'Hello world!'
Give parameter "a" a default value of None. That way if you enter greet(), when your code checks parameter "a", it sees it is none and prints Hello World!
https://code.sololearn.com/cHPh0qK8fep3/?ref=app
+ 4
Your code works fine.
The error being generated is caused by your def(), which is missing the arguments you defined during the set up
+ 3
I am thinking you may need to create an if / else scenario which will determine which of 2 def options to run depending upon the input.
Nice concept to play with
+ 3
Slick Nice!
+ 3
Thanks guys.
+ 2
But...damn! That was Slick😄😃😃
+ 2
By the way, I think a cleaner way to set it up would be this:
def greet(a=None):
print(a or 'Hello World')