Start with hw4pr1.py. Complete a function named first triangle(n) that takes in a single-digit positive integer n (i.e. n…

Start with hw4pr1.py. Complete a function named first triangle(n) that takes in a single-digit positive integer n (i.e. n…

Question:

Transcribed Image Text:

Start with hw4pr1.py. Complete a function named first triangle(n) that takes in a
single-digit positive integer n (i.e. n is between 1 and 9) and displays the triangle
pattern shown in the left sub-figure below: there is no white space in the first row,
all the rows have their last digits aligned, and there is an empty line after the last
row of 1. In the figure below, the middle and right sub-figures are the patterns for
n equal to 3 and 8.
12345. ……….. n
12345…. n-1
12345… n-2
123
12
1

123
12
1
12345678
1234567
123456
12345
1234
123
12
1
Observations and Suggestions:
• Begin each row with zero or more space characters before printing the digits.
• Figuring out a pattern for the proper number of spaces and the following
digit sequence in each row is an important and challenging part of this
problem.
Use small values of n, such as n = 2, 3, and figure out all the details about
each row to identify the pattern.
After identifying the pattern, use the top-down, iterative refinement process
to develop detailed pseudocode before writing Python code.
Test your program with different values of n. Write another function named second_ triangle(n) that takes in a single-digit
positive integer n and displays the following triangle pattern. Notice the empty line
after the last row.
3
32
321
n
n n-1
n n-1 n-2
n n-1 n-2 n-3
n n-1 n-2 n-3 n-4 ….. 4321
Below are the expected outputs for n equal to 3, 5, and 8. Your code should work
for any single-digit positive value of n.
5
54
543
5432
54321
8
87
876
8765
87654
876543
8765432
87654321
Refer to the observations and suggestions on the previous pages for hints. Bonus Problem: complete the function bonus_pattern(n) that takes in a positive
integer n and displays the following pattern, with the figure below showing the
required output of n equal to 10. The four triangles are separated by two spaces.
**
***
***
***
***
**
**
:**

Expert Answer:

Answer rating: 100% (QA)

Answer def first triangle n Check if n is within the valid range if n 1 or n 9 print Please ent
View the full answer