BYU logo Computer Science

To start this assignment, download this zip file.

Homework 4c - Program arguments

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

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.

Grading

ActivityPoints
hello.py2
product.py2
big_words.py8
in_there.py8

Manual grading will focus on decomposition, fluency, division of responsibility between the if __name__ block and the main method, and use of commandline arguments.