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
Your company is planning to storage log data, crash dump files, and other diagnostic data for Azure VMs in Azure. The company ha
Serjik [45]

Answer: Azure Files

Explanation:

Azure Files simply offers file shares in the cloud which can be accessible through the Network File System (NFS) or Server Message Block (SMB) protocol.

Since the administrators must be able to browse to the data in File Explorer, access over SMB 3.0 must be supported and the storage must also support quotas, the Azure files will be useful in this regard.

7 0
3 years ago
general electric always includes an owner registration form with its products. it asks customers for their names, addresses, pho
Marysya12 [62]

The registration, general electric can then sell the information and use it for its own buyer directory. Thus option (A) is correct.

<h3>What is information?</h3>

Information is a general term for everything with the capacity to inform. Information is most fundamentally concerned with the interpretation of what may be sensed. Any naturally occurring process that is not entirely random, as well as any discernible pattern in any medium, can be said to convey some level of information.

An international business based in America is called The General Electric Company (GE). GE has created the technology that will shape the industry for more than 125 years. For its work in the power, renewable energy, aviation, and healthcare sectors, GE is best known today.

Therefore, Thus option (A) is correct.

Learn more about the information here:

brainly.com/question/13629038

#SPJ1

8 0
1 year ago
A Python data model defining the state of a game for Tic-Tac-Toe. You must fully describe the notion of a state of the game, lim
Artist 52 [7]

Answer:

Check the explanation

Explanation:

Here in this game of Tic-Tac-Toe, it is using the TPGE engine which is a Tiny Python Game Engine. Let's talk about its functions like:-

def image_type(img): In this function, it is simply taking image as a parameter and returning its object type like DISC if the image is in graphical form, TEXT if it is a string, and LINE if it is other than the mentioned object.

def convert_image(img):  In this function, it is simply taking image as a parameter and returning an equivalent graphical object as understood by John Zelle's. Mainly comparing for three things in this function and those are: if image equals to DISC then it is calling convert_circle(function), if image equals to LINE then it is calling convert_line(function), and if image equals to TEXT then it is calling convert_text(function),

def convert_circle(x): This function takes a list( a group of values) and makes a circle at the center of the window and the circle's radius is coming from the list.

convert_text, convert_line, convert_circle are only creating text, line, and circle and then returning it.

def graphical_elements(images): This function is taking image as a parameter and then extracting shape and color from the image and then calling convert_image(shape) and convert_type(shape) and it gives us graphic and kind respectively. Now it is checking whether kind equals to DISC If yes then filling color on the window else, setting the outline of the window

def run(): Here it is finally running the game with required parameters, the whole game is continously running under the while loop.

That's all

8 0
4 years ago
.____________ is a way to identify and differentiate goods andservices through use of a name or distinctive design element.
padilas [110]

Answer: Brand

Explanation:

A brand is a way to identify and differentiated the good and services as, brand is the process, which is used for the business and the marketing strategies. Basically, it is used as communication method for distinguished the products and the company for creating the good impression for customers. Brand awareness and management is the main key components.  

3 0
4 years ago
Where in the computer is a variable such as "X" stored?
kow [346]

Answer:

The value of "x" is stored at "main memory".

Explanation:

Simply Central processing unit, input device and output device can not store the data.

7 0
3 years ago
Other questions:
  • Jane is designing a print brochure for a retail company. She’s having trouble deciding on the page margin. Which best practice w
    13·2 answers
  • The use of computer and special software packages to create and edit documents
    11·1 answer
  • Which best describes what Pavel should do differently for the kids book?
    13·2 answers
  • Which method of traversing a tree would result in a sorted list for a binary search tree?
    11·1 answer
  • You work part time at a computer repair store. You are in the process of building a new computer system. The customer wants a mo
    6·1 answer
  • Which statement regarding killers is true?
    12·2 answers
  • TRUE OR FALSE: COMPUTER SCIENCE!
    8·2 answers
  • What is computer virus?​
    12·1 answer
  • WILL MARK BRAIN LIST!
    9·2 answers
  • Which of the following numbers is of type
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!