167k views
5 votes
Write a program that prompts users to enter: A character to use (any character besides *) The width of the display The height of the display to produce an E shape. The middle horizontal line must print at line height/2. This is an example for width of 10 and height of 9 ********** * * *

User Meriem
by
4.2k points

1 Answer

3 votes

Answer:

The solution code is written in Python 3:

  1. input_char = input("Enter a character (except *): ")
  2. width = int(input("Enter a width: "))
  3. height = int(input("Enter a height: "))
  4. checkpoints = [0, height//2 - 1, height-1]
  5. for i in range (height):
  6. if i not in checkpoints:
  7. print(input_char)
  8. else:
  9. output = ""
  10. for j in range(width):
  11. output += input_char
  12. print(output)

Step-by-step explanation:

Firstly, we use input function to prompt use to input a character, width and height (Line 1 -3)

Next we create a checkpoints list to define the line number where the input character should be printed following the width number of times (Line 5).

Next we can create a for-loop to traverse through the number from 0 till height (exclusive of height itself) (Line 7)

If the current i is not found in the checkpoints list, the print function will only display one input character. Else it will print the input character for width number of times(Line 9 -14).

This will eventually result in an E shape.

User Nicholas Pesa
by
4.7k points