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
NARA [144]
3 years ago
15

Write a function that is passed in a positive integer, n, and sum up all the digits from 1 to n, doubling the even numbers. In o

ther words, calculate and return the following sum. if n is odd: 1 (2 * 2) 3 (4 * 2) ... ((n - 1) * 2) n if n is even: 1 (2 * 2) 3 (4 * 2) ... (n - 1) (n* 2)
Mathematics
1 answer:
olya-2409 [2.1K]3 years ago
6 0

Answer:

Written in Python

def sums(n):

    total = 0

    for i in range(1,n+1):

         if i%2 == 0:

              total = total + i*2

         else:

              total = total + i

    return(total)

Step-by-step explanation:

The function is written in Python

def sums(n):

This initializes total to 0

    total = 0

This iterates through the integers that makes up n i.e. 1,2,3.....n

    for i in range(1,n+1):

This checks if current digit is even

         if i%2 == 0:

If yes, it adds the double of the digit

              total = total + i*2

         else:

If otherwise, it adds the digit

              total = total + i

This prints the calculated sum or total

    return(total)

To call the function from main, use the following:

print(sums(n))

Where n is a positive integer. i.e. n \geq 1

You might be interested in
The first five terms in a pattern are shown below.
Fynjy0 [20]

Answer:

I think this answer is A.

Step-by-step explanation:

I think this because when you subtract 0.5-0.25 you get 0.25. So you would add it to whatever comes next until you get to the 9th term. Then you would be somewhere around the ones place. :)

7 0
3 years ago
Ava jayden Edwin Lexi Luis and trina are helping clean up a hiking trail during the summer the trail is 10 miles long each Perso
Marysya12 [62]
Ava is in charge of one and three fiths of the trail.
8 0
4 years ago
Could someone please help me figure this out...
Oduvanchick [21]
<h3>Answer:  29</h3>

====================================================

Work Shown:

The two angles shown are a linear pair. They are adjacent and supplementary. Supplementary angles add to 180 degrees.

(4x-5)+(x+40) = 180

5x+35 = 180

5x = 180-35

5x = 145

x = 145/5

x = 29

--------

As a check, if x = 29, then

4x-5 = 4*29-5 = 116-5 = 111

x+40 = 29+40 = 69

The two angles are 69 and 111 degrees which add to 69+111 = 180, which helps confirm the answer.

6 0
3 years ago
Read 2 more answers
Is 4-6 the same as 4+(-6)? Explain your response.
vova2212 [387]

Answer: Yes, 4-6 is the same as 4 + (-6).

Step-by-step explanation:

One reason why they are the same is because 4 - 6 equals -2 and 4 + (-6) also equals -2. You can turn 4 - 6 into 4 + (-6) by turning the subtraction sign to a plus sign and turn the positive 6 into a negative 6.

4 0
4 years ago
Read 2 more answers
Mitch's father needs 1 and a half tons of gravel he bought 1750 pounds of gravel How many more pounds of gravel does he need??
saw5 [17]
1 and a half tons of gravel is 3000 pounds, so do 3000-1750 and get 1250 pounds of gravel.
3 0
3 years ago
Other questions:
  • What is the value of P? (Need help )
    12·1 answer
  • Evaluate. 3m - n when m = −9 and n = -2
    9·1 answer
  • What is it I don’t know for sure !?
    13·1 answer
  • PS. 99 points will be given What is the volume of the prism? Enter your answer in the box as a mixed number in simplest form. I
    12·2 answers
  • An inequality to compare 16 and 12​
    12·1 answer
  • 52 is 130% of what number
    7·2 answers
  • Show how you can make ten to find the sum 9 + 2 equal
    8·1 answer
  • Find the distance between the two points?<br> <br> (1,2),(7,6)
    8·1 answer
  • if a country's debt to GDP ratio is 92% the country is producing more than it is borrowing true or false
    14·2 answers
  • Line m is mapped onto line n by a dilation centered at the origin with a scale factor of 2. The equation of line m is 3x−2y=63x-
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!