The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Use indentation properly to print the result of the function with an argument of 3. (Python 2)

Use indentation properly to print the result of the function with an argument of 3. (Python 2)

0
Votes
1
Answer

 
 

def ten(x):
    x=10
    return x
print ten(3)

output:

  File "<ipython-input-1-9fb8d4762a52>", line 4
    print ten(3)
            ^
SyntaxError: invalid syntax

After restarting the kernel, result is same the syntax error is occurred. Please help me out of this.
def ten(x):
    x=10
    return x
print ten(3)

OUTPUT:
  File "<ipython-input-1-9fb8d4762a52>", line 4
    print ten(3)
            ^
SyntaxError: invalid syntax
1 Answer

Please add indentation before print statement. It will work .:)

Your code:-

def ten(x):
    x=10
    return x

print ten(3)           [This statement should be indented]

 

Correct code:-

def ten(x):
    x=10
    return x
    print ten(3)    [Indented properly]

 

hope it helps!
Have a good day!:) 🙂


 

it is same.
def ten(x):
x=10
return x

print ten(3)
File “”, line 5
print ten(3)
^
SyntaxError: invalid syntax

6 months
×
LAST CHANCE
Ready to Learn Data Science?
50% OFF