Creating Pyramids with Python Code Examples

Pyramids in Python print('\nNormalPyramid')for i in range(5): x='*' x=x*i print(f'{x:^10}')print('\nInvertPyramid\n')for i in range(5): x='*' x=x*(5-i) print(f'{x:^10}')print('Left sided Pyramid')rows = 5for i in range(1, rows + 1): stars = '*' * i print(f'{stars:<10}')print('\nRightsidedPyramid') rows = 5for i in range(1, rows + 1): spaces = ' ' * (rows - i) stars = '*' * i print(f'{spaces}{stars}')#pythoncode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories