A python program to find the square of the sum of two numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

A python program to find the square of the sum of two numbers

functions

9th Aug 2017, 11:13 AM
Damilare Paul
12 Answers
+ 11
def square_sum(num1, num2): return (num1+num2)**2 # numbers can be modified print square_sum(4, 6) # python 2.x doesn't needs parenthesis in the print statement, maybe that's what causing you problem.
9th Aug 2017, 11:30 AM
Dev
Dev - avatar
+ 3
With Python 2.7 print is a statement, so it's not mandatory to use parenthesis, but they are totally accepted... but in Python 3 print is no more a statement, but a function, so parenthesis are mandatory ^^ The two suggested code would well work... maybe the asker verify them with a wrong case ;P
9th Aug 2017, 12:45 PM
visph
visph - avatar
+ 2
def func (num1,num2): return (num1+num2)**2
9th Aug 2017, 11:15 AM
Dennik
+ 2
What do you need exactly?
9th Aug 2017, 11:23 AM
Vukašin Zeljić
Vukašin Zeljić - avatar
+ 1
Does the given code give any errors, or it doesn't give thе correct output?
9th Aug 2017, 11:29 AM
Vukašin Zeljić
Vukašin Zeljić - avatar
+ 1
Try this code: def square(x, y): x = x + y return (x ** 2)
9th Aug 2017, 11:50 AM
Vukašin Zeljić
Vukašin Zeljić - avatar
0
on python 2.7 I want to know how to write a program that prints the square of the sum of two numbers
9th Aug 2017, 11:26 AM
Damilare Paul
0
Try using the function with parameters 2 and 2. What is the output of that?
9th Aug 2017, 11:40 AM
Vukašin Zeljić
Vukašin Zeljić - avatar
0
(2,2) still
9th Aug 2017, 11:42 AM
Damilare Paul
- 1
not giving the required result
9th Aug 2017, 11:20 AM
Damilare Paul
- 1
yeah, incorrect output
9th Aug 2017, 11:38 AM
Damilare Paul
- 1
I will get back to you later, my PC is down now
9th Aug 2017, 11:54 AM
Damilare Paul