Question

Programming: Python Python homework Triangle: Digital + Right Angle + Reverse Right Angle [Homework 4] Enter...

Programming: Python

Python homework

Triangle: Digital + Right Angle + Reverse Right Angle

[Homework 4] Enter an integer. If it is a positive integer, it will draw a regular triangle; if it is a negative integer, it will draw an inverted triangle.

[Example 1]
Input
1
Output
1
[Example 2]
Input
4
Output
1
2 2
3 3 3
4 4 4 4
[Example 3]
Input
-5
Output
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

§ Please write the program comments, and I hope that the comments can be as detailed as possible.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.


n = int(input())
if n > 0:
    # print the regular triangle
    # start with 1 and end with n
    # here range(start,end) will go to end-1, so use n+1 so that it goes till n
    for i in range(1, n + 1):
        # repeat i with space for i times
        print((str(i) + ' ') * i)
else:
    # print the inverted triangle
    # start with n and repeat till 1, step is -1
    # change sign
    n = -n
    for i in range(n, 0, -1):
        # repeat i with space for i times
        print((str(i) + ' ') * i)

======

Add a comment
Know the answer?
Add Answer to:
Programming: Python Python homework Triangle: Digital + Right Angle + Reverse Right Angle [Homework 4] Enter...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Python and only while loops For this part of the homework you will write code...

    Use Python and only while loops For this part of the homework you will write code to draw an isosceles right triangle. (A right triangle in which the height and base are the same size.) Your program should prompt the user for these inputs, in exactly this order: 1. The height of their triangle 2. The symbol the triangle will be outlined in 3. The symbol the triangle will be filled with For these inputs, you can assume the following:...

  • In C programming language: This program will output a right triangle based on user specified height...

    In C programming language: This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *....

  • Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should...

    Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should meet the following requirements: 1. The program shall graphically prompt the user for a file. 2. The program shall read the selected file which will contain 1 integer per line. 3. The program shall sort the values it reads from the file from largest to smallest. 4. The program shall write the values to an output file from largest to smallest in the same...

  • 5.13 Program: Drawing a half arrow (Python 3) This zyLab activity is the traditional programming assignment,...

    5.13 Program: Drawing a half arrow (Python 3) This zyLab activity is the traditional programming assignment, typically requiring a few hours over a week. The previous section provides warm up exercises intended to help a student prepare for this programming assignment. This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to...

  • I need help with this python programming exercise, please! thanks in advance Create a Python script...

    I need help with this python programming exercise, please! thanks in advance Create a Python script file called hw4.py. Add your name at the top as a comment, along with the class name and date. Both exercises should be in this file, with a comment before each of them to mark it. Ex. 1. Write a program that inputs an integer number from the user, then prints a letter "O" in ASCII art using a width of 5 and the...

  • NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. NO PYTHON...

    NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. NO PYTHON 8 CODE PLEASE.! it's PEP/8 the assembler, nothing to do with python. Write a program in Pep/8 or Pep/9 object code that...

  • Write a program to compute the area of a triangle using side-angle-side method and reports the...

    Write a program to compute the area of a triangle using side-angle-side method and reports the area of that triangle (rounded to 2 decimal places). Side-angle-side formula: ???? = 1/ 2 ?? sin(?), where a and b are two sides of the triangle, and C is the included angle. Your program must meet the following criteria to receive full marks: • Randomly generate two values between 5 and 10 (inclusive) for two sides a and b of the triangle, respectively....

  • byst x Grades for Lewis Dickerson: (Sun X MindTap - Cengage Learning х Python Programming |...

    byst x Grades for Lewis Dickerson: (Sun X MindTap - Cengage Learning х Python Programming | Facebook x war Python: Inp Cengage.com/static/nb/ui/evo/index.html?deploymentid=58296224090012788153144858955&eISBN=9781337560115&id=811000539&snap CENGAGE MINDTAP Programming Exercise 1.7 Instructions myinfo.py ols V- 1 name= input 2 age = int(in 3 print("Alex Write and test a program that accepts the user's name (as text) and age (as a number) as input. . 4 The program should output a sentence containing the user's name and age. S An example of the program input...

  • Python code

    Write a Python program that takes the value of n from the user and calculates the value of S using the following equation:S = 1! - 2! + 3! - 4! + 5! - 6! + ……..  n!Here, the value of n should be a positive (n>0) integer. If the user gives a negative input or zero, then print “Invalid Input!”. Also, print the sentence “End of program.” in the last line no matter what the input is.---------------------------------------------------------------------Sample Input 1:4Sample Output 1:Value of...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT