0

What is the problem? It gives me error

def welcome_message(): print("Welcome,"+name) name=input() welcome_message()

11th Jul 2022, 11:08 AM
Ali Ezzeldeen Gadelrab
Ali Ezzeldeen Gadelrab - avatar
16 Respostas
+ 4
Ali Ezzeldeen Gadelrab There should be space after comma (,)
11th Jul 2022, 12:13 PM
AÍąJ
AÍąJ - avatar
+ 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)
11th Jul 2022, 11:14 AM
Lisa
Lisa - avatar
+ 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.
11th Jul 2022, 3:33 PM
Lothar
Lothar - avatar
+ 3
Thanks both of you It works
11th Jul 2022, 12:14 PM
Ali Ezzeldeen Gadelrab
Ali Ezzeldeen Gadelrab - avatar
+ 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.
11th Jul 2022, 11:37 AM
Lisa
Lisa - avatar
+ 2
It works in code section but in lesson Python for beginners Practice 37.2
11th Jul 2022, 11:46 AM
Ali Ezzeldeen Gadelrab
Ali Ezzeldeen Gadelrab - avatar
+ 2
Lisa You dont need to pass the input
 But he misses an empty space after the comma
12th Jul 2022, 3:22 PM
Janne
Janne - avatar
+ 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."
12th Jul 2022, 3:30 PM
Lisa
Lisa - avatar
+ 1
def welcome_message(name): print("Welcome,"+name) name=input() welcome_message(name) did not work
11th Jul 2022, 11:25 AM
Ali Ezzeldeen Gadelrab
Ali Ezzeldeen Gadelrab - avatar
+ 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.
11th Jul 2022, 12:12 PM
Lisa
Lisa - avatar
+ 1
Thanks
11th Jul 2022, 10:57 PM
Ali Ezzeldeen Gadelrab
Ali Ezzeldeen Gadelrab - avatar
0
The comma needs a space in line 2 :)
13th Jul 2022, 9:40 AM
Viktor Tylus
Viktor Tylus - avatar
0
AAYUSH AGARWAL What? He just missed a space
13th Jul 2022, 1:28 PM
Janne
Janne - avatar
- 2
You should (enter space) after ,
13th Jul 2022, 1:24 AM
SHƂV GΛЛΞSH 10th
SHƂV GΛЛΞSH 10th - avatar
- 2
U give come before double quotes complete
13th Jul 2022, 2:43 AM
Abdul Rahim
Abdul Rahim - avatar
- 2
You should give coma after quotes
13th Jul 2022, 2:43 AM
Abdul Rahim
Abdul Rahim - avatar