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
5/8 multiplied by 4/10 (pls answer asap)​
kykrilka [37]

Answer:Flying potatox x plus y yes

Step-by-step explanation:

8 0
2 years ago
Read 2 more answers
One night, it is 24LaTeX: ^\circ
tatuchka [14]

Answer:

T^\circ  = -12^\circ

Step-by-step explanation:

Given

Represent the temperature in Tucson with T and that in Minneapolis with M.

From the first statement, we have:

T^\circ = M^\circ - 24^\circ

From the second, we have:

T^\circ = -M^\circ or M^\circ = -T^\circ --- i.e. both are opposite numbers

Required

Find T

To calculate T, substitute -T for M in T^\circ = M^\circ - 24^\circ

This gives:

T^\circ = -T^\circ - 24^\circ

Collect Like Terms

T^\circ +T^\circ =- 24^\circ

2T^\circ  =- 24^\circ

Make T the subject

T^\circ  =- 24^\circ/2

T^\circ  = -12^\circ

Hence, the temperature in Tucson is -12^\circ

8 0
3 years ago
What is the range for this set of data?<br> 7, 15, 12<br> O 3<br> O 5<br> O 8<br> O 12
snow_tiger [21]

Answer:

C/8

Step-by-step explanation:

Because the range is the biggest number subtracted by the lowest number and in our data sat 7,15,and 12 15 is the biggest number and 7 is the smallest so what's 15-7?

8 so C

Have a great day.

3 0
2 years ago
1. Find the value of y when x = 3.<br> y = 3(x+7) + 12
Pachacha [2.7K]
Y= 42. 3(3+7)+12
3(10)+12
30+12
42
y=42
7 0
3 years ago
Read 2 more answers
A certain ambulance service wants its average time to transport a patient to the hospital to be 10 minutes. A random sample of 1
jekas [21]

Answer:

C. The claim is not plausible because 10 falls outside of the interval.

8 0
4 years ago
Other questions:
  • An online bank statement reads as follows:
    14·2 answers
  • What is the value of the following expression?2 x [(12 + 2) x 5] + 32 divided by 2 number on top right 3
    8·1 answer
  • Which lists the steps in the correct order to find the median of this data set?
    11·1 answer
  • One side of triangle is 2/8 cm. What is the perimeter
    5·2 answers
  • Choose the example below that can be the first step to factoring by grouping for the following polynomial.
    9·1 answer
  • una pelota se mueve con movimiento uniforme con una velocidad de 0,25 km/seg calcular la distancia que recorre si tarda en llega
    9·1 answer
  • 7m -- 4 for m = 8<br> Evaluate the following algebraic expression
    7·1 answer
  • Four hundred sixty-nine and eight hundredths can also be written as ​
    10·2 answers
  • Examine the following table. Determine whether the rate of change is constant or variable. If it is constant, state the rate of
    12·1 answer
  • What is 1/12 + 7/2 = n ? <br> Please help me! urgent.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!