Start with hw4pr1.py. Complete a function named first triangle(n) that takes in a single-digit positive integer...
Fantastic news! We've Found the answer you've been seeking!
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. ** *** *** *** *** ** ** :** 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 firsttrianglen Check if n is within the valid range if n 1 or n 9 printPlease enter a ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
discuss the role of phenotypic plasticity and phenotypic trait variation in mediating species responses to environmental heterogeneity and disturbance regimes, and how does this phenotypic...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Need help in this homework In this problem, you will learn how to perform an impressivemagic trick. As all tricks, once you understand it, it becomes lessimpressive. But then you can impress other...
-
List the fish and invertebrates you selected after the nitrogen cycling process?
-
Determine the pressure exerted on the surface of a submarine cruising 175 ft below the free surface of the sea. Assume that the barometric pressure is 14.7 psia and the specific gravity of seawater...
-
Using Figure 16.1, write the Fischer projection formula for a. l-arabinose b. l-mannose
-
The pressure distribution measured along a straight, horizontal portion of a 50-mm-diameter pipe attached to a tank is shown in the table below. Approximately how long is the entrance length? In the...
-
Daily samples of 100 power drills are removed from Drill Master's assembly line and inspected for defects. Over the past 21 days, the following information has been gathered. Develop a 3 standard...
-
Consider the choice of buying one of two cars: an electric vehicle (EV), which costs $60,000, and a plug-in hybrid electric vehicle (PHEV), which costs $50,000. Suppose you expect to own the vehicle...
-
5 5 7 B 9 Problem Ithacor Training Inc. started as a single facility for job retraining in Ithaca, New York. The company recently expanded to a new, much larger, second facility in Cortland. The...
-
Suppose now that in addition to the negative wealth effect described in (1), the housing bust triggers severe disruptions in financial intermediation due to financial panics as was the case during...
-
To mitigate a risk on a project, you need to buy and install a piece of equipment. Vendor A sells the equipment for $20,000 and Vendor B sells it for $16,000. If you install the equipment from Vendor...
-
Samantha has the following transactions: . She purchases $5,000 worth of a mutual fund with cash from her savings account. . She spends $6,000 on a vacation with cash from her money market account ....
-
Solve: 2+3 log (x 2) = 4 x= type your answer...
-
3. Suppose that we have an exponential function y = a. bx. How do we know if this function will show exponential growth or exponential decay? (1 point) 4. Suppose that we have a continuous...
-
You are ten days late in your monthly rent's payment. Your landlord tells you that you now also have to pay a "late fee" of $150, in accordance with your lease. You look at your lease and you...
-
Find lim+8f(x): 2+72-120 2-7
-
Maria Castigliani is head of the purchasing department of Ambrosiana Merceti, a medium-sized construction company. One morning she walked into the office and said, The main problem in this office is...
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
If Charles, a 16-year-old child model, earns $50,000 a year and is completely self supporting even though he lives with his parents, can his parents claim him as a dependent? Why or why not?...
-
Larry Gaines, age 42, sells his personal residence on November 12, 2012, for $144,000. He lived in the house for 7 years. The expenses of the sale are $10,500, and he has made capital improvements of...
-
A \(0.40-\mathrm{m}\) wire carries a current of \(1.7 \mathrm{~A}\) and is at angle to a \(0.20-\mathrm{T}\) uniform external magnetic field. What must be the angle between the wire and the magnetic...
-
A square loop of side \(a=50 \mathrm{~cm}\) is suspended from the left arm of a scale, which is kept at equilibrium by adding weights to the right side. The lower half of the loop is in a uniform...
-
A square loop of wire has a perimeter of \(60 \mathrm{~cm}\) and is oriented such that two of its parallel sides form a \(30^{\circ}\) angle with the horizontal. A uniform horizontal magnetic field...
Study smarter with the SolutionInn App