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
Evaluate x(y-z)2 for =-1,y=5,and z=
Nata [24]

Answer:

The value of x(y-z)^2 is -16.

Step-by-step explanation:

We need to evaluate x(y-z)^2 for x = -1, y = 5 and let us assume that z = 1

It can be simply done by putting the values of x,y and z in the given expression.

x(y-z)^2=(-1)(5-1)^2\\\\=-1(4)^2

We know that the value of 4² = 16

So,

x(y-z)^2=16\times -1\\\\=-16

So, the value of x(y-z)^2 is -16.

6 0
4 years ago
Please help with this!
ratelena [41]

Answer:

3/8

Step-by-step explanation:

1/8 + 1/4 = 1/8 + 2/8 = 3/8

Note that 1/4 = 1/4 * 2/2 = 1*2 / 4*2 = 2/8

4 0
3 years ago
Line k has a slope of 2/3. If line m is parallel to line k, then it has a slope of
White raven [17]

Answer:

2/3

Step-by-step explanation: parallel lines have the same slope with different y-int

7 0
3 years ago
Factorisation of ax^2 + bx + c
tigry1 [53]

Answer:

-5(t+3)(t-6)

Step-by-step explanation:

-5²+15+90

= -5(t²-3t-18)

= -5(t+3)(t-6)

6 0
3 years ago
The weight, in pounds, of a newborn baby tt months after birth can be modeled by the equation W=1.75t+6.W=1.75t+6. What is the s
timofeeve [1]

Answer:

-3 x-3

Step-by-step explanation:

4-4=0   -3x-3

5 0
3 years ago
Other questions:
  • Suppose that sin(θ)=6/10 and θ is in the second quadrant. Use trigonometric identities to find the following quantities exactly.
    6·2 answers
  • A fireman used a ladder with 56 rungs. The rungs on the ladder were 15 in. apart and 1.5 in. thick. What is the distance from th
    15·1 answer
  • With an x intercept of 5 and a y intercept of -5
    11·1 answer
  • Y=3x - 7 Y=2x - 6 What does x and y equal
    7·1 answer
  • Ansley is going to help his father shingle the roof of their house. what is the area of the triangular portion of one end of the
    13·1 answer
  • Katy spent $2834 on a washing machine and a dryer. The dryer cost $875 less than the washing machine. How much did the dryer cos
    9·1 answer
  • Find the distance between the points (-1,4) and (2,4).
    8·1 answer
  • Heather is solving an equation by graphing the expressions on either side of the equal sign. If the graph intersects at an infin
    15·2 answers
  • Help ! need an explanation and answer!
    14·2 answers
  • What is. 6(x-1)+3=3x-2(1-x)<br><br> I give Brainliest!
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!