Write a function named foo that has two parameters: n1 and n2. The function returns the outcome of adding up all the numbers above n1 up-to but excluding n2, where each number is raised to the power of itself. See below for an example. Your code must check that n1 is less than n2, and if so use a for loop with a range function. Otherwise, return -1. For example, when we pass 1, and 5 to the function it returns the sum of all integers of 22, 33, 44. But, if we pass 5 and 1, the outcome is -1.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question
Python
Write a function named foo that has two parameters: n1 and n2.
The function returns the outcome of adding up all the numbers above n1 up-to but excluding n2,
where each number is raised to the power of itself. See below for an example.
Your code must check that n1 is less than n2, and if so use a for loop with a range function.
Otherwise, return -1.
For example, when we pass 1, and 5 to the function it returns the sum of all integers of 22, 33, 44.
But, if we pass 5 and 1, the outcome is -1.
Edit View Insert Format Tools Table
12pt v
Paragraph v
BIU A
O words
</> /
Search or type URL
+
...
Transcribed Image Text:Write a function named foo that has two parameters: n1 and n2. The function returns the outcome of adding up all the numbers above n1 up-to but excluding n2, where each number is raised to the power of itself. See below for an example. Your code must check that n1 is less than n2, and if so use a for loop with a range function. Otherwise, return -1. For example, when we pass 1, and 5 to the function it returns the sum of all integers of 22, 33, 44. But, if we pass 5 and 1, the outcome is -1. Edit View Insert Format Tools Table 12pt v Paragraph v BIU A O words </> / Search or type URL + ...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning