Homework 3

Due: November 8, 2019
Points: 100


  1. (50 points) The file bp.csv, available on Canvas, contains seven comma-separated fields. The first line contains headers describing what each field is, and the remainder of the lines contain data. For this problem the following columns are important:
    1. Column 3, the diastolic blood pressure value;
    2. Column 6, the systolic blood pressure value;
    3. Column 7, the pulse pressure; and
    4. Column 5, the patient business identifier.
    For each patient, print the following:
    1. Number of entries for the patient;
    2. Minimum, mean, and standard deviation of the diastolic blood pressure values;
    3. Maximum, mean, and standard deviation of the systolic blood pressure values; and
    4. Maximum, mean, standard deviation, and minimum of the pulse pressure values.
    Create a CSV file with the results. The fields are to be in the following order:

    To turn in: Please call your program bpanalyze.py, and submit it and your CSV file to Canvas.

  2. (50 points) A string is said to be abcdearian if the letters in it, regardless of case, are in dictionary order. So, for example, “almost” and “effort” are abcdearian, and “willow” and “computer” are not.
    1. Write a recursive function called isabcde(s) that returns True if s contains a string that is abcdearian, and False otherwise. The function must ignore any non-letter characters in s, and treat all alphabetic characters as lower case. Note the function must be recursive, and so must call itself.
    2. Write a program that reads a string and uses the function to determine whether the string is abcdearian. The program is to loop until the user types an end of file (control-D), or another exception occurs.

      Here is sample output:

      The string? heLlo↵
      heLlo is not abcdearian
      The string? aLmost↵
      aLmost is abcdearian
      The string? w3i\$l0l!ow↵
      w3i\$l0l!ow is not abcdearian
      The string? e3f\$f0o!rt↵
      e3f\$f0o!rt is abcdearian
      The string? cOmpuTer↵
      cOmpuTer is not abcdearian
      The string? ABcDE↵
      ABcDE is abcdearian
      The string? control-D
      

    To turn in: Please call your program abcde.py, and submit it to Canvas.

Extra Credit

  1. Define the function:
    if x is even, divide by 2; if odd, multiply by 3 and add 1
    The Collatz conjecture says that, if you iterate this sequence for any initial value of n, then eventually the sequence will reach the number 1.

    For a given number n, let k be the least number of iterations needed to reach the number 1 (excluding the initial value). Then k is called the total stopping time of n.

    For example, if n = 29, then the sequence is:

    
    29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
    
    and so the total stopping time of 29 is 18.

    Write a program that takes as input a positive integer and prints both the sequence and the total stopping time for that integer. The output should look like:

    
    29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
    The total stopping time for 29 is 18
    

    To turn in: Please call your program collatz.py and submit it to Canvas


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
ECS 36A, Programming and Problem Solving
Version of October 29, 2019 at 2:09PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh