Lab 1: Part 3: Text in boxes


In this task, you will write a short python program that asks the user to provide a string, and then prints a box of asterisks (*) around the string.

Below are three different runs of your program:

Sample 1:

Enter a string ==> Hi
*     Hi     *

Sample 2:

Enter a string ==> Lovely day today
*     Lovely day today     *

Sample 3:

Enter a string ==> Sometimes you feel like a nut
*     Sometimes you feel like a nut     *

Task A: Get comfy with raw_input

The python built-in function raw_input allows you to ask the user for input.

Try this:

raw_input('Type your name')

Note: you can add an arrow to the prompt, if you like:

raw_input('Type your name ==>')

Let's say the user types 'Selena'. In order to refer to 'Selena' later in your program, you'll need to save it in a variable.

Task B: Draw a box around the user input

Let's take another look at one of our examples from above:

Enter a string ==> Sometimes you feel like a nut
*     Sometimes you feel like a nut     *

There should be 5 spaces of padding on either side of the string in the box (see enlarged image below). Note that your program should work correctly regardless of the length of the provided string.

Task C: Draw a box around TWO user inputs

In this task, the user is asked TWICE to provide strings. Your program will produce a box around both lines of text, with 5 spaces of padding around the longer string in the box. See examples below.

Example 1:

Enter your first string ==> happy

Enter your second string ==> birthday to you!
*     happy                *
*     birthday to you!     *

Example 2:

Enter your first string ==> Row row row your boat

Enter your second string ==> gently
*     Row row row your boat     *
*     gently                    *

Example 3:

Enter your first string ==> Sometimes you feel like a nut

Enter your second string ==> Sometimes you do not
*     Sometimes you feel like a nut     *
*     Sometimes you do not              *

Task D: Get acquainted with Otter Inspect

In this course we use a Python program called Otter Inspect that helps test and give you feedback on your code. Hat tip to the developers of Otter Inspector— Instructor Sravana Reddy and Tutor Daniela Kreimerman Arroyo ('19)

Starting with ps01, Otter Inspect will be used to help verify your problem set code is running as expected.

In order to do this, your pset download folders will include a pre-programmed version of Otter Inspect that is designed to run with that specific problem set.

Otter Inspect will test for the most common cases and expectations, but it might not be comprehensive. Furthermore, Otter Inspect only checks the results of your code— it does not provide feedback for design or code style.

In short: Otter Inspect is there to help you reach the correct solution, but you are responsible for your code and you should always “cross your t's dot your i's” when it comes to testing and checking work before submission.

In this part of today's lab, we want to demonstrate how to use Otter Inspect so you're familiar with it for the problem sets. We'll use our file from the previous task as an example.


In Canopy, open and run lab01/ which will open a new browser window with a page that looks something like this:

Take note of the color legend:

If a Task's button is orange, the numbers displayed tell how many test cases your code passed.

Clicking on the button gives more details about your results.

For example, here is an example of running otterInspect with code that passes all the tests (note the green button):

And here is an example with code that fails all the tests (note the red button):

You may run Otter Inspector as often as you like, the results are solely for your consumption.


Things to check if Otter Inspector is not running as expected:

Honor code

In addition to testing your code, Otter Inspector will also check for an honor code file for each problem set.

Open lab01/ and fill in the requested info. When you next run the Honor Code Form button should be green (i.e. it should pass).

As an example, here's a completed file if President Johnson worked with Dean Velenchik:

Table of Contents