BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Homework 4c - Program arguments

If you have a Windows computer use the guide for the Windows terminal setup to configure your system.

Grading

ActivityPoints
hello.py2
product.py2
big_words.py8
in_there.py8
  • Decomposition (No functions are needed for Hello)
  • -2 points: sys.argv is used outside of if __name__ == "__main__".
  • -2 points: System arguments are not passed into other functions as arguments. See the best practices guide for an example.

1. Hello!

Write a program named hello.py that takes a name as an argument and prints “Hello {name}!”

Examples

$ python hello.py world
Hello world!
$ python hello.py CS110
Hello CS110!

2. Product

Write a program named product.py that takes four numbers as arguments and prints their product.

Examples

$ python product.py 1 2 3 4
24.0
$ python product.py -1 1 -1 1
1.0

3. Big Words

Write a program named big_words.py that takes a minimum word size as an argument.

The program then prompts the user for 5 words:

  • If the length of the word is less than the minimum size, print Too short.
  • Otherwise add the word to the list

After getting 5 words of sufficient size, print the words out.

Follow the prompts and formatting demonstrated in the example.

Example

$ python big_words.py 3
Word: word
Word: cat
Word: at
Too short.
Word: I
Too short.
Word: dog
Word: goat
Word: cow
- word
- cat
- dog
- goat
- cow

4. In there somewhere…

Write a program named in_there.py that takes a short string as an argument.

The the program prompts the user for a guess:

  • If the guess matches the secret string, print You got it! and exit the program
  • If the secret string is a substring of the guess, print It's in there... and continue prompting guesses
  • Otherwise print Nope. and continue prompting guesses

Follow the prompts and formatting of the example.

Example

$ python in_there.py ar
Guess: dog
Nope.
Guess: cougar
It's in there...
Guess: ug
Nope.
Guess: gar
It's in there...
Guess: ar
You got it!

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.

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 that you understand how to use system arguments.
See the quality code section on if __name__ == "__main__":.

RubricPoints
Whitespace1
Naming1
Decomposition4
Intent4
Total10