70.2k views
3 votes
Write a program that prints the block letter “B” in a 7x7 grid of stars like this:

*****
* *
* *
*****
* *
* *
*****
Then extend your program to print the first letter of your last name as a block letter in a 7X7 grid of stars.

User Tiko
by
7.6k points

1 Answer

3 votes

Answer:

  1. output = ""
  2. for i in range(7):
  3. if(i % 3 == 0):
  4. for i in range(5):
  5. output+= "*"
  6. output += "\\"
  7. else:
  8. for i in range(2):
  9. output += "* "
  10. output += "\\"
  11. print(output)

Step-by-step explanation:

The solution code is written in Python 3.

Firstly, create a output variable that holds an empty string (Line 1).

Create an outer loop that will loop over 7 times to print seven rows of stars (Line 2). In row 0, 3 and 6 (which are divisible by 3) will accumulate up to 5 stars using an inner loop (Line 4-5) whereas the rest of the row will only print two stars with each start followed by a single space (Line 8-9) using another inner loop.

At last, print the output (Line 12).

User Peter DeWeese
by
8.5k points

Related questions

asked Aug 27, 2024 111k views
Gprasant asked Aug 27, 2024
by Gprasant
8.2k points
1 answer
4 votes
111k views
1 answer
4 votes
229k views
asked May 5, 2024 165k views
Chynah asked May 5, 2024
by Chynah
8.2k points
1 answer
2 votes
165k views