• Register
2 votes
31 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

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

1 vote
1 answer 19 views
19 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 adamSw 11.3k points
0 votes
1 answer 38 views
38 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 Raphael Pacheco 4.9k points
0 votes
1 answer 471 views
471 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 7 views
7 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 Sheeza 2.9k points
0 votes
1 answer 6 views
6 views
I need to know how to return multiple values from a function in Java.
asked Oct 3 Daniel Anderson 4k points