• Register
2 votes
38 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,240 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: Compiler showed: File "temp.py", line 56 return result SyntaxError: 'return' outside function Where was I wrong?
asked 6 days ago Mashhoodch 5.6k points
1 vote
1 answer 27 views
27 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 73 views
73 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 594 views
594 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 37 views
37 views
Problem: Hi! I recently attempted an online multiple-choice question test. There was a statement that was to be marked as true or false. The statement was: A function cannot return the value of an enumeration type. I marked true but, I am confused. Can anybody here ... , then how can we return an enumeration by a function? An example program will be much helpful if this statement is false. Thanks!
asked Dec 5, 2020 Code Learner 5.1k points
0 votes
1 answer 13 views
13 views
Problem: I have debugged a function that I called contar:, because I am trying to master recursion, but it turns out that, when I debugged it in Dev-C ++, the Call Stack was flushing since it was returned, that left me confused ... I don't know how it works , and also because ... + test (n-1); } } What I want to say is that they explain to me why that function works that way and also what it does.
asked Dec 3, 2020 sasha 5.3k points
0 votes
1 answer 50 views
50 views
Problem: Hi there! I am a bit curious about what happens if I skip the return type in function declaration. Does the compiler generate error or the program executes normally? If it executes normally, what return type is used as function return type by default?
asked Nov 28, 2020 Code Learner 5.1k points
0 votes
1 answer 41 views
41 views
Problem: My code gives error when i execute the file. i need someone to fix the error for me. if (isset($file_root)) { if (!empty(trim($file_root))) { //Error Line echo "test"; } }
asked Nov 5, 2020 prog_learner 2.5k points
0 votes
1 answer 8 views
8 views
Problem: I want to return a string value from a function in C++. I have returned integers from functions but have no idea how to return strings. If someone could help me, it would be appreciated. Thanks
asked Oct 12, 2020 Code Learner 5.1k points
0 votes
1 answer 21 views
21 views
I need to know how to return multiple values from a function in Java.
asked Oct 3, 2020 Daniel Anderson 4k points