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
PLEASE HELP!
larisa [96]

Answer:

D

Explanation:

4 0
3 years ago
Read 2 more answers
Give a real-world example of a selection control structure.
yuradex [85]

An example of selection structure is when a group of people wanted to know the exact  number of days through the use of a data set that has the daily high temperature which ranges from above 80 degrees, and as such, a programmer can use the if-end statement.

<h3>What is an if statement?</h3>

An IF statement is known to be a kind of statement that is executed due to the happening of a specific condition.

Note that IF statements must start with IF and end with the END.

Therefore, An example of selection structure is when a group of people wanted to know the exact  number of days through the use of a data set that has the daily high temperature which ranges from above 80 degrees, and as such, a programmer can use the if-end statement.

Learn more about  if-end statement from

brainly.com/question/18736215

#SPJ1

6 0
2 years ago
what evidence supports the claims that the Taj Mahal is a symbol of historical and cultural glory as well as an architectural ma
belka [17]

Answer:

Taj Mahal

Explanation:

The Taj Mahal is best described in the book; World Wonders Worn Down by Cody Crane.

Go to Page 14 of the attached pdf document and you'd find the write up by Jeffery Batholet.

Cheers

Download pdf
8 0
4 years ago
What is smarta Art ? ​
Montano1993 [528]

Answer:

A SmartArt graphic is a visual representation of your information and ideas. You create one by choosing a layout that fits your message. Some layouts (such as organization charts and Venn diagrams) portray specific kinds of information, while others simply enhance the appearance of a bulleted list.

short ans(SmartArt is a way to turn ordinary text into something more visually appealing. It helps draw attention to important information or make information easier to interpret and understand.)

7 0
3 years ago
A total of 378 tickets were sold for the school play. They were either adult tickets or student tickets. There were 72 fewer stu
Dima020 [189]

Since there were 72 fewer students tickets sold than adults tickets. the number of adult tickets that were sold is 278.

<h3>What is this algebra about?</h3>

Note that:

A total of 378 tickets were sold for the school play.

So:

A + S = 378

S = 2A

A + (2A) = 378

3A = 378

A = 126

If A is 126, then S is double of that, or 252.

126 + 252 = 278

Therefore, Since there were 72 fewer students tickets sold than adults tickets. the number of adult tickets that were sold is 278.

Learn more about tickets from

brainly.com/question/13520667

#SPJ1

7 0
1 year ago
Other questions:
  • Gina is upgrading your computer with a new processor. She installs the processor into your motherboard and adds the cooling syst
    5·2 answers
  • If you need to set up direct deposit, which information from your check would you likely need?
    14·1 answer
  • A ______ or workstation computer is typically used by one or a small number of people to perform everyday productivity tasks, su
    10·1 answer
  • What is a path and how do you know that it is filled and selected
    15·1 answer
  • De que se dio cuenta el sol al participar de la limpieza de playas?
    5·1 answer
  • Redundancy can be implemented at a number of points throughout the security architecture, such as in ________. Group of answer c
    12·1 answer
  • marianne needs to create a version of her slide presentation that does not include all the slides and will be used for a particu
    9·1 answer
  • Define a toString prototype method that returns the cat's name, gender, and age separated by semicolons.
    8·1 answer
  • When right-clicking an object, a ____ menu appears, which contains frequently used commands related to the object.
    7·1 answer
  • One of the users in your company is asking if he can install an app on his company-provided mobile device. The installation of a
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!