livepython.net

270. Python Program to Print a Square of Stars

EasyPhase 1 · Warm-up

This is the first pattern. You need one for loop and * to repeat text, and you know both.

Overview

Pattern programs print shapes with characters. They train you to think in rows: what goes in one row, and how many rows there are.

Problem Statement

Chen makes a small game map. Each tile on the map is a square of stars. Read the size n and print a square: n rows, and n stars in each row, with one space between the stars.

Steps

  1. Read n and turn it into a whole number.
  2. Make one row: a star and a space, n times.
  3. Print that row n times with a loop.

Examples

Example 1. Input 3 gives:

* * *
* * *
* * *

Why: 3 rows, and each row has 3 stars.

Example 2. Input 1 gives:

*

Why: a square of size 1 is one row with one star.

Input

One whole number n (1 or more). 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 of n stars. Every line starts at the left edge, with no space in front. 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* * *

YOUR OUTPUT

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