Question: paython TASKS ( EIGHT Tasks ) 1 . Write a function called sum _ from _ one ( ) that takes an integer and adds

paython TASKS (EIGHT Tasks)
1. Write a function called sum_from_one() that takes an integer and adds up and returns
all the integers from 1 up to that number.
Signature:
def sum_from_one(n):
# your code here
return sum
Examples:
sum_from_one(5)->15
sum_from_one(9)->45
2. Write a function called sum_fivers() that takes an integer and adds up and returns all
the multiples of 5 that are less than or equal to that number.
Signature:
def sum_fivers(n):
# your code here
return sum
Examples:
sum_fivers(5)->5
sum_fivers(19)->30 # 5+10+15
3. Write a function called count_fivers() that takes an integer and counts and returns
how many multiples of 5 there are that are less than or equal to that number.
Signature:
def count_fivers(n):
# your code here
return sum
Examples:
count_fivers(5))->1
count_fivers(19))->3
count_fivers(146))->29
4. Write a function called sum_fromX() that takes two integers, bottom and top, and
adds up and returns all the integers from bottom up to and including top.
Signature:
def sum_ fromX(bottom, top):
# your code here
return
Examples:
sum_fromX(2,3)->5
sum_fromX(2,2)->2
sum_fromX(15,19)->85
5. Write a function called sum_divisors()finds the sum of all the proper factors of an
integer. (Proper factors are all the factors of an integer other than the number, itself.)
Signature:
def sum_divisors(n):
# your code here
return
Examples:
sum_divisors(1)->1 #only 1 divides itself
sum_divisors(5)->6 #5+1
sum_divisors(10)->18 #1+2+5+10
-- MORE TASKS ON NEXT PAGE --
6. Write a function called mystery_sum() that takes one integer parameter, n, and
calculates a "sum" as follows:
For all integers from 1 up to but not including n
For even numbers add the square of the number
For odd numbers, add twice the number
Signature:
def mystery_sum(n):
# your code here
return
Examples:
mystery_sum(4))->12
mystery_sum(13))->436
7. Write a function called mystery_sum2() that takes one integer parameter, n, and
calculates a "sum" as follows:
For all integers from 1 up to but not including n
For even numbers, add the square of half the number
NOTE: Be sure you use integers only!
For odd numbers, add the square of the number
Signature:
def mystery_sum2(n):
# your code here
return
Examples:
mystery_sum2(4))->11
mystery_sum2(13))->377
8. Write a function called bigger_mystery() that takes one integer parameter, n, and
determines which mystery function above generates a larger result.
"SAME" if the two results are the same
"ONE" if mystery_sum() generates a larger result
"TWO" if mystery_sum2() generates a larger result
Signature:
def bigger_mystery(n):
# your code here
return
Examples:
bigger_mystery(5)-> TWO
bigger_mystery(20))-> ONE

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!