Computer Science

# Homework 3e — Tuples

## 1. Student Ratings

Write a program to analyze student ratings of a class you are taking. Each student gives the class a rating from 1 to 10, plus a comment. Ratings can be decimal, such as 7.3. Your program should collect all the student ratings as input, then print the average rating, rounded to 1 decimal place, and then all of the comments in a bulleted list.

Here is an example of the input and output for the program:

``````Enter ratings for this class.
Each rating includes a score and a comment.
Use a blank score to end.
Score: 9.5
Comment: Great class!
Score: 8.3
Comment: Good, but too much homework.
Score: 9.2
Comment: I like the teacher but don't like the material much.
Score: 7.1
Comment: I couldn't stay awake.
Score: 8.8
Comment: I learned a lot because the TAs were awesome.
Score:
Average rating: 8.6
- Great class!
- Good, but too much homework.
- I like the teacher but don't like the material much.
- I couldn't stay awake.
- I learned a lot because the TAs were awesome.``````

Be sure to print the instructions and input prompts as shown.

There is starter code in `student_ratings.py`:

``````def main():
# Write code here
pass

if __name__ == '__main__':
main()``````

Start by decomposing the problem into a set of functions that you can call in `main()`:

FunctionParametersDescription
1.
2.
3.
4.
5.
6.

The number 6 is not intended to represent the number of functions you must have — you may have fewer! Once you have your solution designed, implement these functions. If you need help from the TAs, bring this table with you.

## 2. Personal Library

Write a program to keep track of the books you have read. Each book has a title, author, and number of pages (an integer). Your program should collect all the books you have read, then ask you to enter an author’s name. The program then prints the number of books you have read by that author and the total number of pages you have read by that author.

Here is an example of the input and output for the program:

``````Enter the title, author, and pages of each book.
End with a blank title.
Title: To Kill a Mockingbird
Author: Harper Lee
Pages: 281
Title: Beloved
Author: Toni Morrison
Pages: 324
Title: Jane Eyre
Author: Charlotte Bronte
Pages: 536
Title: Shirley
Author: Charlotte Bronte
Pages: 572
Title:
Enter an author to report on.
Author: Charlotte Bronte
You have read 2 books by Charlotte Bronte.
You have read 1108 pages by Charlotte Bronte.``````

Be sure to print the instructions and input prompts as shown.

You can find starter code in `personal_library.py`:

``````def main():
# Write code here
pass

if __name__ == '__main__':
main()
``````

Start by decomposing the problem into a set of functions that you can call in `main()`:

FunctionParametersDescription
1.
2.
3.
4.
5.
6.

Once you have your solution designed, implement these functions. If you need help from the TAs, bring this table with you.

Write a program to collect grades for an assignment. A grade consists of a student and a score (a float). The program should:

• have the grader enter a bonus as a decimal, e.g. 0.10 to mean 10%
• have the grader enter a cutoff as decimal, e.g. 90
• apply the bonus to every student’s score
• print all of the scores over the cutoff

Here is an example of the input and output for the program:

``````Enter scores for each student.
Enter a blank student name to end.
Student: Sarah
Score: 90
Student: John
Score: 88
Student: Peter
Score: 85
Student: Lana
Score: 80
Student:
Bonus: 0.1
Cutoff: 90
High Scores:
- 99.0: Sarah
- 96.8: John
- 93.5: Peter``````

Be sure to print the instructions and input prompts as shown.

To calculate the bonus, you can use this formula:

``new_score = score *(1 + bonus)``

Round the scores to 1 decimal point after you apply the bonus.

Start by decomposing the problem into a set of functions that you can call in `main()`:

FunctionParametersDescription
1.
2.
3.
4.
5.
6.

Once you have your solution designed, implement these functions. If you need help from the TAs, bring this table with you.

## Tests

Be sure you can pass the tests before you turn in the assignment. Review the guide on using pytest if you need to review using pytest and what to do if a test fails.