Question: def square ( n ) : # handle negative input if ( n < 0 ) : n = - n # Initialize result res

def square(n):
# handle negative input
if (n <0):
n =-n
# Initialize result
res = n
# Add n to res n-1 times
for i in range(1, n):
res += n
return res
# Driver Code
for n in range(1,6):
print("n =", n, end=",")
print("n^2=", square(n))
Can you explain the res part

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!