BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Homework 3c — Lists

1. Alphabetical Split

This program will print out words that are “smaller” and “bigger” than a boundary word, using alphabetical order. Write a program that:

  • Gets a list of words, ending with a blank line.
  • Gets a boundary word.
  • Prints the total number of words.
  • Prints the words that come alphabetically before the boundary word.
  • Prints the words that come alphabetically after the boundary word.

Here is some sample input and output from the program:

Word: fantastic
Word: zip
Word: sad
Word: mark
Word: wood
Word: beautiful
Word: amazing
Word: greatness
Word:
Boundary: honors
You have 8 words
These are small:
fantastic
beautiful
amazing
greatness
These are big:
zip
sad
mark
wood

You can find starter code in words.py.

2. Custom bullets

Write a program that prints a list with a variety of custom bullets. The program should:

  • Get a list of words, ending with a blank line.
  • Get a list of bullets, ending with a blank line.
  • Print the list multiple times, once with each type of bullet.

Here is some sample input and output for the program:

Item: Soul
Item: Incredibles
Item: Brave
Item: Wall-e
Item: Finding Nemo
Item: A Bug's Life
Item:

Custom Bullet Point: *
Custom Bullet Point: o
Custom Bullet Point: -
Custom Bullet Point:

* Soul
* Incredibles
* Brave
* Wall-e
* Finding Nemo
* A Bug's Life

o Soul
o Incredibles
o Brave
o Wall-e
o Finding Nemo
o A Bug's Life

- Soul
- Incredibles
- Brave
- Wall-e
- Finding Nemo
- A Bug's Life

Hint: print(), with no arguments, will print an empty line.

You can find starter code in custom_bullets.py.

3. Compare lists

Write a program that compares how many fruits you eat with how many vegetables you eat. The program should:

  • Get a list of fruits, ending with a blank line.
  • Get a list of vegetables, ending with a blank line.
  • If the list of fruits is longer:
    • Prints the list of fruits
    • Prints the list of vegetables
    • Prints “You need more vegetables!”
  • If the list of vegetables is longer:
    • Prints the list of vegetables
    • Prints the list of fruits
    • Prints “You need more fruit!”
  • If the lists are the same length:
    • Prints the list of fruits
    • Prints the list of vegetables
    • What a healthy balanced diet! (the lists are equal lengths)
  • To get full credit, you must write and use a generic function (see Lab 3c - Shopping List for an example) to query the user for both lists.

Here is some sample input and output for the program:

Enter a Fruit: apple
Enter a Fruit:
Enter a Vegetable: carrot
Enter a Vegetable: squash
Enter a Vegetable:
Vegetables:
 - carrot
 - squash
Fruits:
 - apple
You need more fruit!

You can find starter code in compare_lists.py.

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.

Grading

ActivityPoints
Alphabetical split6
Custom bullets7
Compare lists7

Manual Grading

Refer to the Quality Code guide page for detailed explanations and examples on each of these rubric criteria.

Intent

The intent of this assignment is for you to use generic functions to create and print lists.

Your functions should be similar to what is shown in lab3b.
See the lab solutions if needed.

Generic functions will be expected for most assignments after this one. The ability to write generic functions is a major learning outcome of this class.

Decomposition

Rereading the section on decomposition from the quality code guide is a good idea at this point in the course.

RubricPoints
Whitespace1
Naming1
Decomposition4
Intent4
Total10