1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Effectus [21]
3 years ago
12

Write a recursive function sumSquares(num) that given an integer num, returns the sum of squares of numbers from 1 to num. For e

xample: sumSquares(3) should return 1^2 2^2 3^2

Computers and Technology
1 answer:
ValentinkaMS [17]3 years ago
4 0

Answer:

Here is the recursive function sumSquares(num) that takes an integer num as parameter and returns the sum of squares of numbers from 1 to num.

def sumSquares(num):

   if(num >= 0):  # checks if the value of num is less than or equal to 0

       if (num==0):  #if value of num is 0

           return 0  #returns 0 if value of num is 0

       else:  #if value of num is greater than 0

           return sumSquares(num - 1)+ num * num  #recursively calls the sumSquares method to return the sum of squares of numbers from 1 to num

   else:  # if a user enters a negative num

       (print("The number if not positive"))  #prints this message

       exit()  # exits after displaying that number if not positive message

#below print statement is used in order to check the working of the function        

print(sumSquares(3)) #calls function and passes value 3 for num

Explanation:

The program works as follows:

The function sumSquares(num) that takes an integer num as parameter and returns the sum of squares of numbers from 1 to num

The first if condition checks if value of num is positive. If this condition evaluates to true then the another if statement inside this if statement is executed which checks if the value of num is 0. If this condition evaluates to true then the program returns 0. However if this condition evaluates to false then the else part executes which has the following statement:

return sumSquares(num - 1) + num * num

For example num = 3

so the above recursive statement works as follows:

sumSquares(3-1) + 3 * 3

sumSquares(2) + 9

Note that the sumSquares() method is called again and the value 2 is passed as num. As 2 is greater than 0. So again the recursive statement executes:

sumSquares(2 - 1) + 2 * 2 + 9

sumSquares(1) + 4 + 9

sumSquares(1) + 13

sumSquare() method is called again and the value 1 is passed as num. As 1 is greater than 0. So again the recursive statement executes:

sumSquares(1 - 1) + 1 * 1 + 13

sumSquares(0) + 1 + 13

sumSquares(0) + 14

sumSquare() method is called again and the value 0 is passed as num

As the value of num=0 So the if (num == 0):  condition evaluates to true and the statement returns 0 executes which returns 0:

sumSquares(0) + 14

0 + 14

Hence the output is:

14

The screenshot of the program along with its output is attached.

You might be interested in
Match the installation type to its description.
MariettaO [177]

Answer:

Following are the types of installation matched to its respective definitions.

<h3>Upgrade installation:</h3>

What you do when you have a computer with an existing operating system that needs to be upgraded.

This means that while working on a window when you get attracted by the update introduced recently and you upgrade your window accordingly.

For example: Updating a window from 8 to 10 or desired features.

<h3>Multiple boot installation:</h3>

What you do when you have several operating systems on one computer.

In this type of installation, a computer has different windows for different accounts. You can boot to the desired installed window by switching account.

<h3>Clean installation:</h3>

What you do on a brand new computer that has never been set up before and does not have an operating system on it yet.

It can be defined as the installation of window done very first time on to the computer. Sometimes when the window gets deleted due to virus or any other factor, the installation at that time will also be termed as Clean Installation.

<h2>I hope it will help you!</h2>
5 0
3 years ago
A company's computers monitor assembly lines and equipment using ________ communications.
mr_godi [17]

Answer:

Machine to machine communications

Explanation:

Machine to machine communication is a type of communication that exists among the technical devices. The communication is linked either with the help of wire or through wireless. The information is communicated and transmitted with this form of communication. Human involvement or intervention is not required during the transfer of data.

6 0
4 years ago
NWhen you measure a person’s weight, you are measuring the
MAVERICK [17]

Answer:

gravitational force acting on that person.

Explanation:

5 0
3 years ago
Read 2 more answers
Which of the following is the safest authentication method?
myrzilka [38]

The safest authentication method is authentication using a smart card.

Smart Card Authentication uses a physical card along with a smart card reader and software on the workstation to validate users into enterprise resources like workstations and applications. Although smart card authentication offers a terrible user experience and is expensive to deploy and maintain, it is very secure.

Because smart card authentication requires a physical credential, a hardware card reader, and software, it is expensive and difficult to administer. Smart cards are only used in the most secure workplaces, such as three-letter agencies of the federal government or privileged access at a financial institution, as these environments frequently forbid employees from carrying smartphones to and from work.

To learn more about Authentication click here:

brainly.com/question/17217803

#SPJ4

6 0
1 year ago
The number of square units required to cover a surface.
dolphi86 [110]
This depends on the length, width, and sometimes height.
5 0
3 years ago
Other questions:
  • Which of the following statements is correct? A. The columns will be listed in the results in the same order they are stored in
    7·1 answer
  • On the Internet, you can use a(n)______to look for information on any topic, such as books, movies, scholarly articles, news, an
    6·2 answers
  • Which phase takes all the detailed design documents from the design phase and transforms them into the actual system? Testing ph
    7·1 answer
  • Which business document is usually written in block style with the body tedt aligned along its left margin?
    9·1 answer
  • This document shows a student's education and career goals and a way to achieve those goals.
    8·1 answer
  • An application calculates an ending inventory amount based on a beginning inventory amount, sales, and returns. You need to crea
    8·1 answer
  • 3. In a 32-bit CPU, the largest integer that we can store is 2147483647. Verify this with a
    12·1 answer
  • The programming interface for a legacy motor controller accepts commands as binary strings of variable lengths.
    15·1 answer
  • I have crummy WiFi and a bad pc. If I get a gaming computer, will it improve my FPS or ping?
    14·2 answers
  • Host A sends a packet of length 1,100 bytes to host B over a link with transmission rate 4 Mbps over a distance 1300 km, propaga
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!