CPSC 115L: Introduction to Computing Spring 2010

Homework 4

CPSC 115-01: due Monday, October 4
CPSC 115-02: due Tuesday, October 5

1. Exam statistics

Design and implement a Python script to solve the following problem: given a number of exam scores in the range 0 to 100, report the average score and the numbers of A's, B's, C's, D's and F's. For this, complete the following two exercises.

1.1. First, design and implement a Python script to report just the average score. Your script should behave as follows:
What is the size of the class?  5

Now enter the scores below.

Student 1: 79
Student 2: 87
Student 3: 67
Student 4: 96
Student 5: 83

The average is 82.4.
Your script should be able to process any number of exam scores. If the user specifies the class size to be n, then your script should prompt for exactly n exam scores. As usual, first write down your I/O specification and algorithm. Then implement your algorithm in a Python script named exam1.py. Run your script with five test cases and save the snapshots of your test runs in a text file named exam1.out.

2.2. Next, extend your solution to 2.1 to count the numbers of A's, B's, C's, D's and F's. Assume that letter grades are assigned according to the standard grading scale: A corresponds to 90–100, B corresponds to 80–89, and so on. Your script should behave as follows:
What is the size of the class?  5

Now enter the scores below.

Student 1: 79
Student 2: 87
Student 3: 67
Student 4: 96
Student 5: 83

The average is 82.4.

There are 1 A's.
There are 2 B's.
There are 1 C's.
There are 1 D's.
There are 0 F's.
For this, redesign your I/O specification and algorithm. Then implement your algorithm in a Python script named exam2.py. Run your script with five test cases and save the snapshots of your test runs in a text file named exam2.out.

2. Recursion

Recall the recursive function countdown discussed in §5.8 of Downey. This function performs a countdown from any given integer, one step at a time, down to one. Complete the following three exerices. Implement all in a script named recursion.py, with five tests for each function. Save the output in a text file named recursion.out.

2.1. Modify the function countdown so that, instead of printing numerical values, it prints asterisks in the following way. Your function must be recursive and must not use any loops.
>>> countdown(5)
*****
****
***
**
*
Blastoff!
To print n copies of *, put print '*' * n.

2.2. Next, by modifying your solution to 2.1, implement a function named start that prints asterisks in the increasing order in the following way. Again, your function must be recursive and must not use any loops.
>>> start(5)
Start!
*
**
***
****
*****
2.3. Now, implement a function named recursive_pattern that prints asterisks in the following way. Again, your function must be recursive and must not use any loops.
>>> recursive_pattern(5)
*****
****
***
**
*
**
***
****
*****

What to hand in

Submit the following in paper. Be sure to put a file header at the top of each file.

Plagiarism and academic dishonesty

Please remember our course policy on plagiarism and academic dishonesty: You are encouraged to consult with one another when you work on homework assignments, but in the end everyone must do one's own work to hand in. In particular, discussion of homework assignments should be limited to brainstorming and verbally going through strategies, but it must not involve one student sharing written solutions with another student. In the end everyone must write up solutions independently. If you have discussed with classmates or used any outside source, you must clearly indicate so on your solutions and provide all references. Turning in another person's work under your name is plagiarism and qualifies as academic dishonesty. Academic dishonesty is a serious intellectual violation, and the consequences can be severe. For more details, read the Student Handbook 2010–2011, pp. 21–29.


* CPSC 115L home page
Valid HTML 4.01!