Hollow Inverted Half Pyramid - 2
Given the number of rows N, write a program to print the hallow inverted half pyramid pattern similar to the pattern shown below.
1 2 3 4 5
1 4
1 3
1 2
1
Input
The input will be a single line containing a positive integer (N).
Output
The output should be N rows containing the numbers in the hollow inverted half pyramid pattern.
Note: There is a space after each number.
The media company "GlobalAd" has received a
batch of advertisements from different product
brands. The batch of advertisements is a
numeric value where each digit represents the
number of advertisements the media company
has received from different product brands.
Since the company banners permit only even
numbers of advertisements to be displayed, the
media company needs to know the total
number of advertisements it will be able to
display from the given batch.
Write an algorithm to calculate the total
number of advertisements that will be
displayed from the batch.
Input
The input consists of an integer batch,
representing the batch of advertisements
Output
Print an integer representing the total number
of advertisements that will be displayed by the
media company
Constraints
0 < batchs 109
Part 2
Invent your own function that does some useful computation of your choosing. Do not copy the function from somewhere else. Use incremental development, and record each stage of the development process as you go. Finally, print output that demonstrates that the function works as you intended.
Include all of the following in your Learning Journal:
Part 1
Section 6.2 of your textbook describes incremental development. Do the exercise at the end of that section:
As an exercise, use incremental development to write a function called hypotenuse that returns the length of the hypotenuse of a right triangle given the lengths of the other two legs as arguments. Record each stage of the development process as you go. (Downey, 2015)
After the final stage of development, print the output of hypotenuse(3, 4) and two other calls to hypotenuse with different arguments.
Include all of the following in your Learning Journal:
def factorial(n):
space = ' ' * (4 * n)
print(space, 'factorial', n)
if n == 0:
print(space, 'returning 1')
return 1
else:
recurse = factorial(n-1)
result = n * recurse
print(space, 'returning', result)
return result
space is a string of space characters that controls the indentation of the output. Here is the
result of factorial(4) :
factorial 4
factorial 3
factorial 2
factorial 1
factorial 0
returning 1
returning 1
returning 2
returning 6
returning 24
If you are confused about the flow of execution, this kind of output can be helpful. It takes
"Debugging" lists three possibilities to consider if a function is not working.
For this question
Add two polynomials
Given two polynomials A and B, write a program that adds the given two polynomials A and B.
if the in puts are
4
0 5
1 0
2 10
3 6
4
0 -5
1 0
2 -10
3 -6
then the result is 0 but it is not showing the result from the code of Question #175894
Respond to the following question in at least three well composed paragraphs: What are the necessary conditions for a monopoly position in the market to be established?
Section 6.9 of your textbook ("Debugging") lists three possibilities to consider if a function is not working.