Question

For Python: Complete the function sum_v2 that takes an integer n as input parameter and computes...

For Python: Complete the function sum_v2 that takes an integer n as input parameter and computes the sum of all odd integers between 5 and n (inclusively). Use FOR LOOP only and NO IF STATEMENTS.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Here is the function:

Explanation:
We can use the third argument inside range function, which defines the step by which i is increased.

So, i will be increased by 2 at everystep.


def sum_v2(n):
res = 0
for i in range(5, n+1, 2):
res = res+i
return res


print(sum_v2(11))
  

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

Add a comment
Know the answer?
Add Answer to:
For Python: Complete the function sum_v2 that takes an integer n as input parameter and computes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT