Week 2 Programming Assignment
- You may define additional auxiliary functions as needed.
- In all cases you may assume that the value passed to the function is of the expected type, so your function does not have to check for malformed inputs.
- For each function, there are normally some public test cases and some (hidden) private test cases.
- "Compile and run" will evaluate your submission against the public test cases.
- "Submit" will evaluate your submission against the hidden private test cases. There are 12 private test cases, with equal weightage. You will get feedback about which private test cases pass or fail, though you cannot see the actual test cases.
- Ignore warnings about "Presentation errors".
A positive integer m is a prime product if it can be written as p×q, where p and q are both primes. .
Write a Python function primeproduct(m) that takes an integer m as input and returns True if m is a prime product and False otherwise. (If m is not positive, your function should return False.)
Here are some examples of how your function should work.
>>> primeproduct(6) True >>> primeproduct(188) False >>> primeproduct(202) True
Write a function delchar(s,c) that takes as input strings s and c, where c has length 1 (i.e., a single character), and returns the string obtained by deleting all occurrences of c in s. If c has length other than 1, the function should return s
Here are some examples to show how your function should work.
>>> delchar("banana","b") 'anana' >>> delchar("banana","a") 'bnn' >>> delchar("banana","n") 'baaa' >>> delchar("banana","an") 'banana'
Write a function shuffle(l1,l2) that takes as input two lists, 11 and l2, and returns a list consisting of the first element in l1, then the first element in l2, then the second element in l1, then the second element in l2, and so on. If the two lists are not of equal length, the remaining elements of the longer list are appended at the end of the shuffled output.
Here are some examples to show how your function should work.
>>> shuffle([0,2,4],[1,3,5]) [0, 1, 2, 3, 4, 5] >>> shuffle([0,2,4],[1]) [0, 1, 2, 4] >>> shuffle([0],[1,3,5]) [0, 1, 3, 5]
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | primeproduct(6) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | primeproduct(188) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 3 | primeproduct(202) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 4 | delchar("banana","b") | anana | anana\n
| Passed after ignoring Presentation Error |
Test Case 5 | delchar("banana","a") | bnn | bnn\n
| Passed after ignoring Presentation Error |
Test Case 6 | delchar("banana","n") | baaa | baaa\n
| Passed after ignoring Presentation Error |
Test Case 7 | delchar("banana","an") | banana | banana\n
| Passed after ignoring Presentation Error |
Test Case 8 | shuffle([0,2,4],[1,3,5]) | [0, 1, 2, 3, 4, 5] | [0, 1, 2, 3, 4, 5]\n
| Passed after ignoring Presentation Error |
Test Case 9 | shuffle([0,2,4],[1]) | [0, 1, 2, 4] | [0, 1, 2, 4]\n
| Passed after ignoring Presentation Error |
Test Case 10 | shuffle([0],[1,3,5]) | [0, 1, 3, 5] | [0, 1, 3, 5]\n
| Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Test Case 6 | Passed |
Test Case 7 | Passed |
Test Case 8 | Passed |
Test Case 9 | Passed |
Test Case 10 | Passed |
Test Case 11 | Passed |
Test Case 12 | Passed |
No comments