A document from MCS 260 Fall 2021, instructor Emily Dumas. You can also get the notebook file.

MCS 260 Fall 2021 Homework 12

  • Course instructor: Emily Dumas

Instructions:

  • Complete the problems below, which ask you to write Python scripts.
  • Upload your python code directly to gradescope, i.e. upload the .py files containing your work. (If you upload a screenshot or other file format, you won't get credit.)

Deadline

This homework assignment must be submitted in Gradescope by 10am CST on Tuesday, November 16, 2021.

Topic

This homework assignment focuses on regular expressions, software licensing, and testing with pytest.

Collaboration

Collaboration is prohibited, and you may only access resources (books, online, etc.) listed below.

Resources you may consult

The course materials and other resources you are allowed to refer to for this homework are:

(Lecture videos are not linked on worksheets, but are also useful to review while working on worksheets. Video links can be found in the course course Blackboard site.)

Point distribution

This homework assignment has 2 problems, numbered 2 and 3. Thus the grading breakdown is:

Points Item
2 Autograder
4 Problem 2
4 Problem 3
10 Total

What to do if you're stuck

Ask your instructor or TA a question by email, in office hours, or on discord.

( 1. There's no problem 1 )

Gradescope will show the results of the automated syntax check of all submitted files as the score for problem 1.

2. Mentions of 7400-series ICs

In the 1970s and 1980s, one of the most popular series of components in digitial electronic circuits were the 7400 series of integrated circuits. They were used extensively in early personal computers, for example. They are still used in some electronics applications. Here's a picture of a few of them:

There are many parts in this series, with numbers like 7404 and SN74LS02N and 74F08.

More precisely, the format of the part number is

  • Some capital letters (possibly 0 of them)
  • The digits 74
  • Some more capital letters (possibly 0 of them)
  • Two or three digits (e.g. 00, 01, 04, 26, 138, 193)
  • Some more capital letters (possibly 0 of them)

Write a program hwk12prob2.py that takes a filename as its command line argument. It should read the lines of the specified text file and look for names of 7400-series ICs matching the specs above. It should print each name it finds.

Restricted methods note

  • You must use regular expressions to do the searching/matching
  • You can only use Python syntax and techniques we've covered in MCS 260

Example

If test.txt contains

I was thinking about the clock module we discussed, and I think by adding a couple of JK-type
flip-flops (maybe 74LS107 or SN74LS72N? not sure...) we could convert the momentary pushbutton
input to a toggle, without using the more mechanically complicated sustained switch your BOM
originally called for.  But I agree we should keep using dedicated inverters on a 7404 rather
than repurposing an unused NAND from the 74HC00, since it will be a pain to interface the TTL
and CMOS parts to make that work.

then the output of

python3 hwk12prob2.py test.txt

would be

74LS107
SN74LS72N
7404
74HC00

3. Test dice

Create test_dice.py, a module containing pytest-compatible functions to test the module dice.py we created in lecture 23.

The tests should do the following:

  • Check that rolling a 12-sided die returns an integer between 1 and 12
  • Check that rolling 10 dice returns a list of 10 integers, all between 1 and 6
  • Check that the return value of the coin flip function is either "heads" or "tails"

For full credit, your module must have three passing tests that can be discovered and run by pytest if test_dice.py and dice.py are in the same directory. Also, if test_dice.py is run as a script, it must do nothing at all.

Restricted methods note

  • The only module you are allowed to import in test_dice.py is dice
  • You can only use Python syntax and techniques we've covered in MCS 260

Revision history

  • 2021-11-11 Initial release