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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started