Question: intro level python/data programming Problem 3: Triangular numbers Use a for loop to compute the 10th triangular number. The nth triangular number is defined as
Problem 3: Triangular numbers Use a for loop to compute the 10th triangular number. The nth triangular number is defined as 1+2+3+...+n. (You can also compute the nth triangular number as n(n+1)/2. Use this formula to double-check that your loop is correct.) Hint: This outline is an almost-complete solution. You only have to replace each ellipsis by an expression. n = 10 triangular - 0 for i in ...: triangular = print("Triangular number", n, "via loop:", triangular) print("Triangular number", n, "via formula:", n. (n + 1) / 2) Your code should be able to correctly calculate the 11th, 12th, or any other triangular number just by changing the first line to set n to 11, 12, or any other number. Be sure the code you submit calculates the triangle number for n - 10. Using the range function should help you accomplish this. Problem 4: Factorial ... Use a for loop to compute 101, the factorial of 10. Recall that the factorial of n is 1'2"3...n. [Note: you may not use the math.factorial function for this problem or any other problem in this homework. You should also NOT use recursion. (If you do not know what that means, do not worry because you should not use it :-) Hint: Your answer will be similar to your answer to "Problem 3: Triangular numbers". As in Problem 3, your code should be able to calculate 111, 121, or any other number's factorial just by changing the first line to set n to 11, 12, or any other number. Be sure the code you submit calculates the factorial for n = 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
