Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

Start with hw4pr1.py. Complete a function named first_triangle(n) that takes in a single-digit positiveWrite another function named second_triangle(n) that takes in a single-digit positive integer n and displaysBonus Problem: complete the function bonus_pattern(n) that takes in a positive integer n and displays the

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. ** *** *** *** *** ** ** :**

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Answer def firsttrianglen Check if n is within the valid range if n 1 or n 9 printPlease enter a ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions