1.8k views
0 votes
Program Specifications Write a program that outputs a downwards facing arrow composed of a rectangle and a right triangle. Arrow

dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. Note: this program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only
a portion of tests pass after each step but confirm progress. Step 1 (3 pts). Input the arrow base height (int) and width (int). Draw a rectangle using asterisks (height x width), Hint: use a nested loop in which the inner loop draws one row of *s, and the outer loop iterates a number of times equal to the height. Submit for grading to confirm
two tests pass.
Ex: If input is:
6 4
Sample output is:
Step 2 (3 pts). Input the arrow head width and draw a right triangle. Hint: use a nested loop. Submit for grading to confirm four tests pass.
Ex: If input is:
4 3 4
Sample output is:

User SeanR
by
8.2k points

1 Answer

5 votes

Here's a Python code that generates a downwards-facing arrow using the specified dimensions: arrow base height, arrow base width, and arrowhead width.

The Code

def draw_arrow(base_height, base_width, head_width):

# Print arrow base (rectangle)

for i in range(base_height):

print('*' * base_width)

# Print arrow head (right triangle)

for i in range(head_width, 0, -1):

print('*' * i)

# Example: Arrow dimensions - base height: 4, base width: 4, head width: 6

draw_arrow(4, 4, 6)

This program defines a draw_arrow function that prints the arrow base as a rectangle of specified height and width, followed by the arrow head as a right triangle with the specified width. The function is called with example dimensions to demonstrate the arrow's structure.

User WetlabStudent
by
8.9k points