alex7881
27.11.2019 •
Engineering
Sum of numbers design a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. for example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, . . 50. use recursion to calculate the sum. demonstrate the function in a program.
Solved
Show answers
More tips
- S Style and Beauty How to Choose the Perfect Hair Color?...
- C Computers and Internet Best iPad Games: Our Opinion...
- A Animals and plants Man s Best Friend: Which Dog Breed Is the Most Friendly?...
- H Health and Medicine 10 Simple Techniques on How to Boost Your Mood...
- G Goods and services How to Choose the Right High Chair for Your Baby?...
- S Style and Beauty Learn how to tie a keffiyeh on your head like a pro...
- S Style and Beauty How to braid friendship bracelets?...
Answers on questions: Engineering
- E Engineering This age was marked by the revival of classical influence and the sharing of ideas...
- M Mathematics Evaluate -3w -2p for w=7 and p= -3...
- H History Select the correct locations on the graph. The bar diagram shows average rainfall for periods of 50 years. Study the bar diagram and Identify the two periods in which a civilization...
- H History When it comes to work, which points of view are shown to be different from Buck s early in these chapters? Select all that apply. Spitz Billee Dave Sol-leks...
- C Chemistry A solution is made by adding 25 mL of benzene to 80 mL of toluene. What is the percent by volume of benzene?...
- S Social Studies Which statement does this picture best support? Early humans created decorative arts such as jewelry. The skeleton shows someone who was a skilled hunter. The skeleton shows...
- B Business Type the correct answer in the box. Spell all words correctly. What is the forecasted sale of ice cream in the month of November using the 4-period moving averages?...
- W World Languages Есе на тему : яка роль навчання в житті людини...
- H Health Match the type of knife with proper usage. PLEASE HURRY TIMED TEST...
- M Mathematics What is the length, in units, of X? 4 units Х 12 units Enter your answer in the space provided. Round your answer to the nearest tenth of a unit. units HELP PLEASE...
Ответ:
# define main to get an argument from the user, call the function, and display the final values
def main():
# ask an argument from the user.
number = int(input('Enter a positive integer: '))
# solve the integral thing of the number by putting the user's argument in the addition() function
finalSum = addition(number)
# display the final value integral thing
print("The integral of this number is ", finalSum, ".")
# define an addition function to find the integral
def addition(num):
# make an if-statement to test filter things out of your calculations. In this case, 1.
if num == 1:
#if 1, return 1. because 1 + (1 - 1) = 1
return 1
# this is where the recursion actually is. This is the part that calculates
else:
return num + addition(num-1)
# call your main function
main()
Explanation:
This is written in Python. A link to the output can be found below.
https://Sum-of-Numbers.hufflepuffler07.repl.run
Ответ:
ok
Explanation: