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
amm1812
4 years ago
12

Write a function called sum_first_integers that takes a single positive integer parameter. The function should also return a pos

itive integer. In particular, it should return the sum of the positive integers from 1 to the value passed into the function. For example, if 5 is passed into the function, it should return 15 because that is the number you get when you add 1 + 2 + 3 + 4 + 5. Hint: We recommend using the range function and a for loop.
Computers and Technology
1 answer:
sashaice [31]4 years ago
6 0

Answer:

def sum_first_integers(n):

       if n <= 0 or type(n) != int:

               raise ValueError('Value must be a positive integer greater than 0')

       total = 0

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

               total += num

       return total

Explanation:

The above function was written in Python, the first if statement is for validation purposes and it ensures that the argument passed is a positive integer. If it is not, a ValueError is raised

We leveraged on Python's range function, which accepts three arguments although we passed in two arguments. The first argument is where the range function will start from and the second is where it will end. If we want the range function to stop at value n, then the argument has to be n+1(This is because machine starts counting numbers from 0) and the last argument is the step in which the increment is done. If no value is passed to this argument, Python assumes the value to be 1 which is what is done in this case.

Hence range(1, 5) = (1,2,3,4) and range (2, 10, 2) = 2,4,6,8

You might be interested in
Select two netiquette guidelines. In a paragraph of no less than 125 words, explain why these guidelines make professional onlin
Paladinen [302]

Respect others.

This means that it is important to make sure that your interactions with other internet users are based on respect for each other's resources. This includes time, bandwidth, and even emotions. Ensure that the information you are sharing is of value to the intended recipients and is sent in a timely manner. Treat other online users as you'd have them treat you.

Visualize your online conversations as you would real life conversations. Avoid being offensive and be accommodating of other peoples shortcomings. Also keep in mind who is part of the forum you are interacting with so as to use appropriate language. 



4 0
3 years ago
If you try to add a new item to a full stack the resulting condition is called a(n)?
Butoxors [25]

Answer:

it's called an overflow

3 0
2 years ago
Effective note-taking helps support<br><br> action.<br> distinction.<br> distraction.<br> retention.
zloy xaker [14]
It is the last one retention because writing it out will cause it to stick in your brain better
7 0
3 years ago
Read 2 more answers
can somebody please explain to me why I woke up today to see that all of my 40 answers where deleted ? like what I spent hours
Alina [70]
Same on my other account
They took my brainly and my answrs
Left me with thanks and a lil point
What going on???
4 0
3 years ago
Read 2 more answers
Panes created using the vertical split bar scroll together horizontally. true or false.
Nataly_w [17]
I think the statement given above is false. Panes created using the vertical split bar do not scroll together horizontally. <span>The two </span>panes scroll together vertically, but scroll<span> independently </span>horizontally<span>. Hope this answers the question. Have a nice day.</span>
4 0
3 years ago
Other questions:
  • Which data type uses more memory an integer or an unsigned integer?
    6·1 answer
  • To change to the completed application’s directory, we opened a command window and used the ________ command to change to the di
    7·1 answer
  • Which of the following is generally nota desire today's workers? A. computer ability B willingness to learn C. teamwork skills D
    8·1 answer
  • 6.   If you enter 234.567 into a cell that is formatted to display 1 decimal place, what is the value stored in the cell?
    15·2 answers
  • I'm looking for a new laptop for school. Which laptop would be the best. Right now I have a chromebook and it is broken. 
    12·2 answers
  • )finding an unused location in the hash table is called
    5·1 answer
  • Is it possible to have a deadlock involving only oneprocess? Explain your answer.
    11·1 answer
  • What values can represent a bit
    8·1 answer
  • Fill in the blank
    13·1 answer
  • Project stem test 3 answers
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!