0
What is the problem? It gives me error
def welcome_message(): print("Welcome,"+name) name=input() welcome_message()
16 ответов
+ 4
Ali Ezzeldeen Gadelrab
There should be space after comma (,)
+ 6
You did not pass the input to the function.
Have a look at this version and compare it to your own:
def welcome_message(name):
print("Welcome,"+name)
name=input()
welcome_message(name)
+ 5
def welcome_message():
print("Welcome,"+name)
name=input()
welcome_message()
the above code is working fine, even if we have not passed the variable 'name' as argument to the function 'welcome_message()'.
>>> what is the reason of this behaviour?
to make it clear, in python we do not necessarely need to pass a variable to a function.
the variable 'name' is used with the input() function in the main part of the code, before we call the function 'welcome_message(). the only statement in this function is print("Welcome,"+name).
since there is no local variable 'name' defined in the function, the value from the outer scope will be used.
+ 3
Thanks both of you
It works
+ 2
Go to Code section, click +, select the programming language, insert the code, run it.
You'll see that the code works.
If you are referring to a task in a sololearn course, please mention course name and task number. Read the task description again.
+ 2
It works in code section but in lesson
Python for beginners
Practice 37.2
+ 2
Lisa You dont need to pass the input… But he misses an empty space after the comma
+ 2
Janne Yes, that's true.
My intention – as it seemed to be a beginner task on functions – was: "Do not mess with global variables unless you know what you are doing."
+ 1
def welcome_message(name):
print("Welcome,"+name)
name=input()
welcome_message(name)
did not work
+ 1
I cannot access this task, can you please share the task description?
Your output needs to be formatted exactly as in the task description. That means if there is a blank space in the example, your code needs this blank space, too.
+ 1
Thanks
0
The comma needs a space in line 2 :)
0
AAYUSH AGARWAL What? He just missed a space
- 2
You should (enter space) after ,
- 2
U give come before double quotes complete
- 2
You should give coma after quotes