• Register
2 votes
54 views

Problem:

Hello folks, I was trying to write a simple program where it will add two numbers but I am getting error.
Can you please dig into it and let me know where I am being wrong?

 

# Python 3 Code

def myfunction(a, b):
  # Print the value of a+b
  add = a + b
return(add)

# Print values in list
print('Addition: ', myfunction(10, 34));

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes
 
Best answer

Solution:

As I can see your code is not indented properly. You’ve put your return function outside of the condition. The compiler is reading your code before the return, and can’t proceed on and giving you the error message. You always have to the return inside your myfunction.

I am editing your code a little and put the return statement inside your function so that it can run correctly.

# Python 3 Code

def myfunction(a, b):
  # Print the value of a+b
  add = a + b
  return(add)

# Print values in list
print('Addition: ', myfunction(10, 34));

Now you can see the code indented properly and the return statement is just inside the function. This program will run and print

Addition:  44

For further understanding, you may go through the link

 

13 9 6
94,260 points

Related questions

0 votes
1 answer 40 views
40 views
Problem: Compiler showed: File "temp.py", line 56 return result SyntaxError: 'return' outside function Where was I wrong?
asked Jan 9 Mashhoodch 13k points
1 vote
1 answer 43 views
43 views
Problem: Hello good souls, I am an entry-level student of Python programming. I recently started learning python. I’ve created a python function that should calculate the multiplication value of two numbers and returns it. But the script is not executing and produces an error of ... # Calculate the value of a*b mul = a * b return(mul) print('Multiplication is: ', is_a_mul_fuc(10, 5));
asked Jun 15, 2020 adamSw 11.3k points
0 votes
1 answer 7 views
7 views
Problem: I get: SyntaxError: 'break' outside loop Why?
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 105 views
105 views
Problem: uncaught syntaxerror: cannot use import statement outside a module.
asked Feb 15 Ethan ross 2.7k points
0 votes
1 answer 3 views
3 views
Problem: I have defined a function that will get a value from the user input. It's a path (based on the appJar's .directoryBox). I have put the code for the directory box to popup inside a function so that it will show when a button is pressed. However, I cannot seem ... 'Search') app.go() I try to use the 'dirr' variable outside of the dirfunction, but I cannot make it work. It only works within.
asked Apr 24 Humaira ahmed 50.7k points
0 votes
1 answer 9 views
9 views
Problem: please help me to solve... syntax error: non-declaration statement outside function body
asked Apr 1 Ifra 34.7k points
0 votes
1 answer 19 views
19 views
Problem: block-scoped declarations (let, const, function, class) not yet supported outside strict mode
asked Feb 23 Muneeb Saadii 130k points
0 votes
1 answer 126 views
126 views
Problem: I have written the following class: class Foo { private:     static float scale; public:     static float setScale(float scale); }; If I try to implement the setScale() function as shown below: float Foo::setScale(float scale) {    this->scale = ... still throws the same error. Now I am really confused about the above error message as my function in question is already marked as static.
asked Aug 13, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 815 views
815 views
Problem : I am running Laravel 5.4 on my Homestead vagrant box but when I want to run npm run production I am getting the following error block-scoped declarations (let, const, function, class) not yet supported outside strict mode.
asked Nov 14, 2019 peterlaw 6.9k points
0 votes
1 answer 5 views
5 views
Problem: I wrote this code in lib/helper.js. I got an error: Syntaxerror: await is only valid in async function What is the issue?
asked Mar 22 ummesalma 29.2k points