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
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:
| Test | Result |
|---|---|
| beeBop(7) | 1 2 Bee Bop 5 Bee |
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 |
|---|---|
| print(factorial(-1)) | None |
| print(factorial(0)) | 1 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
