Lesson 3.5 · Write it
Print stars
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 number and prints that many stars on a single line.
- Read one number on a single line.
- Print a line of exactly that many
*characters, with nothing between them. - Use a loop to build the line one star at a time. Do not use string repetition (
*on a string in Python, or.repeatin Java).
The number is always 1 or more. Your program is run several times. Only what it prints is checked.
You cannot use these in this question:
- .__mul__()
- .__rmul__()
This question is about using a for loop, so string repetition shortcuts are not allowed.
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.
You cannot use these in this question:
- .repeat()
This question is about using a for loop, so string repetition shortcuts are not allowed.
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.
five stars (rule 2)
You type
- typed: 5
It prints
*****
one star (rule 2)
You type
- typed: 1
It prints
*
four stars (rule 2)
You type
- typed: 4
It prints
****