Click here to Skip to main content
14,239,876 members
Rate this:
Please Sign up or sign in to vote.
See more: , +

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
Rate this:
Please Sign up or sign in to vote.

Solution 1

= is the assignment operator. You want ==, the equality operator.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

' = ' this is used for assignment operator,,

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

and check you ' code indentation '
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

' = ' this is used for assignment operator,,

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

and check you ' code indentation
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100