Sale!

Assignment 3 Functions and Lists

$30.00

Category:
Rate this product

COMP 1005/1405
Assignment 3
Functions and Lists
Submit a single zip file called assignment3.zip.
This assignment has 30 marks.
See the marking rubric that is posted on the course webpage
Problem 1 (Prime Numbers)
Write a function called isprime which takes a single integer argument and returns a
single Boolean value representing whether the given argument is prime (True) or not
(False). After writing the function, test it by using a loop to print out all the prime
numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5,
7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97. Put
your function and testing code inside a file called prime.py and add it to your
submission zip file.
Problem 2 (Common Multiples)
Write a function called ismultiple which takes 2 integer arguments (a and b). This function must
return True if b is a multiple of a (i.e., a divides into b evenly) and False otherwise. Write a
second function called commonmultiple which takes 3 integer arguments (a, b, and c). This
function must return True if c is a multiple of both a and b, and False otherwise. Additionally,
the commonmultiple function must use two calls to the ismultiple function to compute its
return value. Once you have implemented both functions, include testing code that asks the
user to enter two numbers (a and b) and prints out all numbers between 1 and 100 (inclusive)
that are common multiples of a and b. Save your functions and testing code in a file called
multiples.py and add it to your submission zip file.
Problem 3 (List Slicing Function)
Python provides slicing functionality for lists, but for this question, you will implement your own
function capable of producing list slices (note: you cannot use the slicing operator in your
solution). The function should be called slice and take the following three arguments in this
specific order:
1. A list, source, which the slice will be created from. This list cannot be modified by your
function.
COMP 1005/1405 – S17 – A3 Due Sunday, May 28 at 11:55 PM
2
2. A positive integer, start, representing the starting index of the slice you will create. If this
value is not in the range [0, len(list)-1], your function should return an empty list.
3. A positive integer, end, representing the ending index of the slice you will create. If this
value is not in the range [start, len(list)-1], your function should return an empty list.
If the parameter values are acceptable, your function will return a list that contains the items
from source beginning at the index start and ending at the index end (inclusive). This is
different from the Python slice operator, as the item at the index end is also included in the new
list. Examples:
mylist = [“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”]
slice(mylist, 0, 9) should be [“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”]
slice(mylist, 3, 4) should be [“D”, “E”]
slice(mylist, 4, 3) should be [ ]
slice(mylist, 3, 8) should be [“D”, “E”, “F”, “G”, “H”, “I”]
slice(mylist, 4, 4) should be [“E” ]
Save your code is a file called slice.py and add it to your submission zip.
Recap
Your zip file should contain your prime.py, multiples.py, and slice.py files.
Submit your assignment3.zip file to cuLearn.
Make sure you download the zip after submitting and verify the file contents.

Open chat
Need help?
Hello
Can we help you?