livepython.net

282. Python Program to Print a Plus Sign of Stars

EasyPhase 1 · Warm-up

You know for loops, if and the // sign. That is all you need here.

Overview

A plus sign has a full middle row and one star in the middle of every other row. To draw it, you find the middle first.

Problem Statement

Zara paints a first-aid sign for a school trip box. Read an odd whole number n and print a plus sign of n rows:

  • The middle row is n stars, with no spaces in front and no spaces between them.
  • Every other row has one star in the middle. In front of it are n // 2 spaces.

Steps

  1. Read n and turn it into a whole number.
  2. Work out the middle: n divided by 2, with the part after the point dropped.
  3. Loop over the rows.
  4. In the middle row, print n stars. In every other row, print the spaces and one star.

Examples

Example 1. Input 5 gives:

  *
  *
*****
  *
  *

Why: 5 // 2 is 2, so each single star has 2 spaces in front of it. The middle row is row 3, with 5 stars.

Example 2. Input 3 gives:

 *
***
 *

Why: 3 // 2 is 1, so the top and bottom rows have 1 space and a star.

Input

One odd whole number n, 3 or more (3, 5, 7 and so on). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

n lines. The spaces at the start of a line matter: the tests check them. A space at the end of a line is fine: the tests ignore it. The tests try 4 different inputs.

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

Finish this chapter firstChapter 10 · For Loops
solution.py
# write your code here

EXPECTED OUTPUT

1 *
2 *
3*****
4 *
5 *

YOUR OUTPUT

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