livepython.net

283. Python Program to Print a Name Banner in a Box

EasyPhase 1 · Warm-up

No loop is needed here. You know input(), len() and how * repeats text, and that is enough.

Overview

A box around text must grow with the text. len() tells you how wide to make it, so the box fits any name.

Problem Statement

Priya makes name cards for the desks at a club meeting. Read a name and print it in a box of three lines:

  • Line 1 is a row of stars. It has len(name) + 4 stars.
  • Line 2 is a star, a space, the name, a space and a star.
  • Line 3 is the same row of stars as line 1.

Print the name exactly as it was typed.

Steps

  1. Read the name as text.
  2. Count its characters with len() and add 4.
  3. Make a row of that many stars.
  4. Print the row of stars, then the middle line, then the row of stars again.

Examples

Example 1. Input Ana gives:

*******
* Ana *
*******

Why: "Ana" has 3 letters, so the rows of stars have 3 + 4 = 7 stars. That is as wide as the middle line.

Example 2. Input Li Wei gives:

**********
* Li Wei *
**********

Why: "Li Wei" has 6 characters, because the space counts too. So the rows of stars have 10 stars.

Input

One line: the name (1 character or more). It may have spaces in it. Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

Three lines: a row of stars, the name in its frame, and the same row of stars. The tests try 5 different inputs.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 8 · If Statements

This is the last question of Phase 1 · Warm-up. The next question starts Phase 2.

solution.py
# write your code here

EXPECTED OUTPUT

1*******
2* Ana *
3*******

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.