Question: 7.10 REQUIRED - LAB 7B: Drawing a right triangle This program will output a right triangle based on a user specified height triangle_height and symbol
7.10 REQUIRED - LAB 7B: Drawing a right triangle
This program will output a right triangle based on a user specified height triangle_height and symbol triangle_char.
Using what you know about incremental programming and breaking down a problem into manageable pieces, do the following:
The program prompts the user for two values, a character and a height. The initial code does not use these values. Instead, the given program outputs a fixed-height triangle using the * character. Run the program and make sure you understand the code. Then modify the given program to output a right triangle that instead uses the user-specified triangle_char character.
Next, modify the program to use a loop to output a right triangle of height triangle_height. The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional character until the number in the triangle's base reaches triangle_height. Output a space after each user-specified character, including a line's last user-specified character.
Hints: Think about how to repeat a string to make a new string. There are several ways to do that. You can use string concatenation to add on to a string, or the * operator to repeat strings.
If you have a string called my_string which contains 'ab',
new_string = my_string + 'ab'
will result in 'abab' being stored in new_string. Likewise, if you start with my_string containing 'ab', then
new_string = my_string * 3
will result in 'ababab' being stored in new_string
Example output for triangle_char = % and triangle_height = 5:
Enter a character: % Enter triangle height: 5 % % % % % % % % % % % % % % %
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
