The Student Room Group

Coding help

def greet_name(name,greeting):
name = input("Name: ")
greeting = input("Greeting: ")
return("Hello," + name + "! I wish you" + greeting

print(greet_name(name,greeting))

Why is this code not working?
does the second line need to be indented? then it brings up an error for your last line saying "invalid syntax"
I've only recently started learning python so I can't help much more than that :colondollar:
Reply 2
Your function takes in 2 parameters (name, greeting), but you haven't defined them before your function call. As you're assigning the variables inside the function, they're not required.


def greet_name():
name = input("Name: ")
greeting = input("Greeting: ")
return("Hello," + name + "! I wish you" + greeting)

print(greet_name())

something like that will work.
(edited 3 years ago)
What you want inside the def needs to be indented.
Your function is taking in two parameters which are both unused, and undefined. You don’t need these as even if you did define them as their values get overridden when you ask for user input. Remove these parameters from the function definition and when you call it within the print function.
(edited 3 years ago)

Quick Reply

Latest

Trending

Trending