About 4,500,000 results
Open links in new tab
  1. python - Draw a triangle out of asterisks using for loops - Stack Overflow

    Feb 15, 2015 · Use (size + 1)//2 to get an integer. Because (size+1)/2 could theoretically have a fractional part, Python always returns a floating point number from it. range doesn't accept floats because there is no general way to turn it into an integer without potentially losing information.

  2. ascii art - Asterisk triangle in python - Stack Overflow

    Mar 22, 2013 · I have to write a recursive function asterisk_triangle which takes an integer and then returns an asterisk triangle consisting of that many lines. For e.g this is a 4 line asterisk triangle.

  3. triangle of asterisks using for loops : r/learnpython - Reddit

    One that increase the asterisk by 1 for each iteration. Therefore we can achieve this effect with a for loop and range. For i in range(1, n): print(i*"*") We take advantage of the increasing variable to create the right triangle! Next I would suggest looking into trees or equilateral triangles to print.

  4. python - Asterisk Triangle - Stack Overflow

    Mar 20, 2016 · Here's a cool trick - in Python, you can multiply a string by a number with *, and it will become that many copies of the string concatenated together. >>> "X "*10 'X X X X X X X X X X ' And you can concatenate two strings together with + :

  5. Printing Pyramid Patterns in Python - GeeksforGeeks

    Mar 3, 2025 · Adjust the value of num_rows to change the size of the hollow inverted half pyramid. Python def print_hollow_inverted_half_pyramid ( rows ): for i in range ( rows , 0 , - 1 ): for j in range ( rows - i ): print ( " " , end = "" ) for j in range ( i ): if j == 0 or j == i - 1 or i == rows : print ( "*" , end = "" ) else : print ( " " , end ...

  6. Draw Triangle with Asterisks in Python - CodePal

    This Python code demonstrates how to draw a triangle using asterisks (*) and fill the inside with asterisks as well. The function takes a size parameter, which represents the number of rows in the triangle. It first verifies that the size is valid, raising a ValueError if it is less than 2.

  7. Python Nested Loop Triangle Pattern - CodePal

    Learn how to create a triangle pattern using nested loop structures in Python. This pattern consists of rows of increasing and decreasing asterisks. Follow the step-by-step guide and practice your coding skills.

  8. Write code that causes a "triangle" of asterisks of size

    Feb 17, 2018 · You can make use of the print() function in Python to show the asterisks on the screen. Here is an example of the code: # Define the size of the triangle n = int(input('Enter the number of lines: ')) # Loop through from 1 to n for i in range(1, n + 1): print('*' * i)

  9. Draw an asterisk triangle - Code Golf Stack Exchange

    Oct 10, 2016 · Loops from 1 to input $args, each iteration using string multiplication to construct a string of that many $_ asterisks. Default behavior for the implicit Write-Output at the end is with a newline for separator, so we get that for free.

  10. Python Programs to Print Patterns – Print Number, Pyramid, Star ...

    Sep 3, 2024 · To achieve this, we utilize two loops: outer loops and nested loops. The outer loop is the number of rows, while the inner loop tells us the column needed to print the pattern. The input () function accepts the number of rows from a user to decide the size of a pattern.

Refresh