CP103: Assignment 06 - Winter 2025

Due 8:30 AM, Monday, March 10, 2025

Tasks

Create a project folder username_a06. Place all your tasks python files(t01.py , t02.py ,t03.py) and the testing file testing.txt inside this folder. Upon completing your tasks, export your projrct folder to username_a06.zip file, validate it, and submit it to the dropbox by the due date.

  1. Write and test the following function:

            
    def winner():
    
          

    Add the function to a Python module named functions.py. Test it from .

    winner takes no parameters and asks the user to enter a series of strings that represent the output of a game with a loop. The user should enter an empty string (just press or ) to signal the end of the series. After all strings have been entered, the function returns two numbers representing how many times the string "blue" appeared in the input and how many times the string "grey" appeared in the input.

    The function must use a while loop.

    Provide the function docstring (documentation) following the CP103 style.

    Sample execution:

            winner()
          
    Enter the winning team: blue
    Enter the winning team: blue
    Enter the winning team: grey
    Enter the winning team: blue
    Enter the winning team: grey
    Enter the winning team:
    

    and returns:

    3, 2
    

    Test the function with three different sets of parameters.

    Partial testing:


    Results


  2. Write and test the following function:

            
    def is_prime(num):
        """
        -------------------------------------------------------
        Determines if num is a prime number.
        Use: prime = is_prime(num)
        -------------------------------------------------------
        Parameters:
            num - a positive integer (int > 1)
        Returns:
            prime - True if num is prime, False otherwise (bool)
        ------------------------------------------------------
        """
    
          

    Add the function to a Python module named functions.py. Test it from .

    A prime number is a positive integer greater than 1 which has no other factors except 1 and the number itself. 2, 3, 5, and 7 are prime numbers as they can only be divided by 1 and by themselves to give a whole number. 4 is not a prime because, 4 can be divided by 1, 2 and 4.

    The function does not ask for input and does no printing - that is done by your test program.

    The function must use a while loop.

    Sample execution:

            
    is_prime(9)
          
    False
            is_prime(131)
          
    True
    

    Test the function with three different sets of parameters.

    Partial testing:


    Results


  3. Write and test the following function:

            
    def interest_table(principal, rate, payment):
        """
        -------------------------------------------------------
        Prints a table of monthly interest and payments on a loan.
        Use: interest_table(principal, rate, payment)
        -------------------------------------------------------
        Parameters:
            principal - original value of a loan (float > 0)
            rate - yearly interest rate as a % (float >= 0)
            payment - the monthly payment (float > 0)
        Returns:
            None
        ------------------------------------------------------
        """
    
          

    Add the function to a Python module named functions.py. Test it from .

    The function must use a while loop.

    Sample execution:

            interest_table(1000, 10, 100)
          
    Principal:   $1000.00
    Interest rate : 10.0%
    Monthly payment: $100.00
    ----------------------------------
    Month Interest   Payment   Balance
    ----------------------------------
        1     8.33    100.00    908.33
        2     7.57    100.00    815.90
        3     6.80    100.00    722.70
        4     6.02    100.00    628.72
        5     5.24    100.00    533.96
        6     4.45    100.00    438.41
        7     3.65    100.00    342.07
        8     2.85    100.00    244.92
        9     2.04    100.00    146.96
       10     1.22    100.00     48.18
       11     0.40     48.58      0.00
    

    Test the function with three different sets of parameters.

    Partial testing:


    Results


Partial testing of functions.py:


Results

Partial testing of testing.txt:


Results