Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THREE QUESTIONS - USE PYTHON LANGUAGE 5. Use the Design Recipe to write a functi

ID: 3728696 • Letter: T

Question

THREE QUESTIONS - USE PYTHON LANGUAGE

5. Use the Design Recipe to write a function called mySum with one parameter, assumed to be a non-negative integer. Return the sum of all integers between 0 and this number, inclusive. Do not use the built-in sum function.

6. Use the Design Recipe to define a function called beeBop that accepts an integer called num. The function prints each number from 1 to num (exclusive) on a new line. For each multiple of 3, print "Bee" instead of the number. For each multiple of 4, print "Bop" instead of the number. For numbers which are multiples of both 3 and 4, print "BeeBop" instead of the number.

For example:

7. The factorial of a (positive) integer is the product of each of the integers from 1 to the given integer.

For example, 3! = factorial(3) = 3*2*1 = 6.

Use the Design Recipe to write a function factorial that when given a positive integer calculates the factorial. If given a negative integer), the function should return None. If given 0, it should return 1.

For example:

Test Result beeBop(7) 1
2
Bee
Bop
5
Bee

Explanation / Answer

def mySum(n): sum = 0 for i in range(0, n+1): sum += i return sum def beeBop(n): for i in range(1, n): if i % 3 == 0 and i % 4 == 0: print("BeeBop") elif i % 3 == 0: print("Bee") elif i % 4 == 0: print("Bop") else: print(i) def factorial(n): if n < 0: return None if n == 0 or n == 1: return 1 else: return n*factorial(n-1) print(mySum(10)) beeBop(7) print(factorial(-1)) print(factorial(0)) print(factorial(5))