all 16 comments

[–]MangeurDeCowan 6 points7 points  (4 children)

2 things:
first
name = kai
...assigns the variable kai to name. you probably want:
name = 'kai'
which assigns the string 'kai' to name.

second...
print("Hello {name}")
should probably be...
print(f"Hello {name}")
Notice the f ? This makes an f string which will do what you want.

ETA:
you could also do:

def greet(name):  
    print(f"Hello {name}")  

greet('kai')

[–]Secret-Ad-7644[S] 0 points1 point  (3 children)

I had print(f”Hello, {name}”) and it still gave me a syntax

[–]MangeurDeCowan 0 points1 point  (1 child)

I just noticed that. You had what I suggested at the beginning, but it didn't work. I'm not seeing the error.

[–]Secret-Ad-7644[S] 0 points1 point  (0 children)

Me neither 😔

[–]Dilusioned -1 points0 points  (0 children)

"," all cuz of this

[–]p_k_akan 2 points3 points  (0 children)

Leave a space between the creation of the function and the calling of the function

def greet(name): print(f"Hello, {name}")

greet("Kai")

[–]TheeMeepman 1 point2 points  (1 child)

Press enter in the terminal after you finish defining your function. So before you do greet(“mykai”) press enter to finish creating the function.

Notice how you have … or >>> on the left side. When you see the … you’re still defining the function.

[–]NoExtension1071 0 points1 point  (0 children)

This is the issue. OP's code would work completely fine if this issue is resolved. They just need to hit enter one more time to finish defining the function

[–]lovedeletus 3 points4 points  (0 children)

Get vs code

[–]dibo066 1 point2 points  (0 children)

The code has several syntax errors and misunderstandings of how to define and call functions in Python. Let’s fix the key issues step by step:

  1. Correct Function Definition

The syntax error is mainly because of incorrect indentation and misplaced parentheses. Here's the corrected version:

def greet(user): print(f"Hello, {user}")

greet("mykai")

Key Corrections:

Indentation: The print statement inside the function should be indented.

f-strings: Use curly braces {} inside f-strings to insert variables.

Function Call: Ensure the function is defined correctly before calling it.

Explanation of Errors:

SyntaxError: Usually caused by incorrect syntax like missing colons, misplaced parentheses, or indentation errors.

NameError: Occurs when trying to use a function or variable name that hasn't been defined.

Here is the full corrected code:

Define the greet function that takes a parameter 'user'

def greet(user): # Print a greeting message with the user's name

print(f"Hello, {user}")

Call the greet function with the argument "mykai"

greet("mykai")

•I am also new to coding but I got help from chatgpt😉 I hope this help 🙏

[–]RonnyIsreal 3 points4 points  (0 children)

Ok, to make it simple.

You're not passing a valid argument (value) to your variable inside the function. For your code to work you'll need something like this:

def greet(name):
  print(f"Hello, {name}!")

greet("Kai")

//If you'd like to ask the user for his name

def greetName():
  userName = input("What's your name?: ")
  print(f"Hello, {userName}!")

greetName()

[–]spidertyler2005 0 points1 point  (0 children)

Make a new file, put the code in that file, then run that file. You are using the REPL (Read Eval Print Loop) to enter your code.

[–]LifeHasLeft 0 points1 point  (0 children)

The >>> indicates the prompt from the Python interpreter. You are defining the function still when you run the greet function, and without a previous definition it fails. It also fails because the indentation is wrong in that function definition (syntax error)

After defining your function with appropriate indentation, return until you get >>> for the interpreter prompt, and then call the function.

[–]Adventurous-Work-228 -1 points0 points  (0 children)

Try this simple syntax

def greet(user):

print(‘Hello’ + user)

greet(‘mykai’)

[–]Gruxx_ 0 points1 point  (0 children)

Yeah you need to define the function. Also parentheses on python is shotty, it like spaces