Lesson 4.1 · Write it
Greeting with a border
A whole programPython or Java6 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a name and prints a greeting framed by two identical border lines.
- Read one name on a single line.
- Print
----------(ten hyphens) on the first line. - Print
Hello,followed by the name, then!on the second line. - Print
----------(ten hyphens) on the third line.
Define a function that prints the border line, and call it for both borders.
The name is always one word. Your program is run several times. Only what it prints is checked.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
a name with a border above and below (rules 2, 3, 4)
You type
- typed: Alice
It prints
---------- Hello, Alice! ----------
a different name (rule 3)
You type
- typed: Bob
It prints
---------- Hello, Bob! ----------
a single-character name (rule 3)
You type
- typed: X
It prints
---------- Hello, X! ----------