HW 11

Programming: create a file primes.py and copy the following isprime() function into it:

def isprime(num):
    """ This returns True if the given int is prime, and False otherwise. """
    if num <= 1:
        return False

    for i in range(2, num//2+1):
        if num % i == 0:
            return False

    return True    # If we reached here, then no divisor was found.

You must now define 2 more functions in primes.py. Add them below the provided isprime(num) function. You'll want to use isprime(num) for the second one:

  1. Write a function countz(List) that takes a List of strings as an argument. It then counts how many of those strings contain the letter z (upper or lower case). Return the number of strings in the list which contain at least one z or Z.
    # This code should print the number 4
    words = [ "The", "zoo", "waz", "full", "of", "pandaz", "but", "OH", "NOEZ", "they", "died." ]
    zees = countz( words )
    print(zees)
  2. Write a function next_prime(int) that takes one integer as an argument, and then returns the next biggest integer that is prime. If the argument is prime, don't return it, find the next biggest.
    # This code should print the number 17
    next = next_prime(14)
    print(next)

    HINT: You can put the above code in your program (after your function definitions of course)! Run it and see if your functions produce the correct result! Once you are confident, remove the testing code and ONLY submit your file with three defined functions.

Submit

Submit your psearch.py to the online submission system under hw11-primes.
Make sure it has 3 function definitions, and nothing else in it.

submit -c=sd211 -p=hw11-primes primes.py