Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Python


My code:

Quote:
def dave_check(user_name):
if user_name= "Dave" :
return "Get off my computer Dave!"


# Enter a user name here, make sure to make it a string
user_name = "Dave"

print(dave_check(user_name))

The result:

File "C:/Users/jaide/PycharmProjects/HelloWorld/venv/app.py", line 2
    if user_name= "Dave" :
                ^
SyntaxError: invalid syntax


What I have tried:

I have tried to change it to
Quote:
if user_name="Dave":
even this did not work. I know that dealing with the spaces really dosent matter but just tried it.
PLEASRE HELP ME UNDERSTAND THE ERROR
Posted
Updated 11-Jul-19 16:09pm

= is the assignment operator. You want ==, the equality operator.
 
Share this answer
 
' = ' this is used for assignment operator,,

but you need ' == ' for comparison .. thats why it show an invalid syntax error ..

and check you ' code indentation '
 
Share this answer
 
' = ' this is used for assignment operator,,

but you need ' == ' for comparison .. thats why it show an invalid syntax error ..

and check you ' code indentation
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900