Question: Java Python bgoldner@northseattle.edu > double_sum prev next chance Write a function that is passed in a positive integer, n, and sum up all the digits

 Java Python bgoldner@northseattle.edu > double_sum prev next chance Write a function

Java Python bgoldner@northseattle.edu > double_sum prev next chance 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 other 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) double_sum(5) 21 double_sum(10) double_sum(1) 1 85 Bad code Don't print, compute and return ar Go ...Save, Compile, Run (ctrl-enter) def double_sum (n)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!