- # shapes.py
- """ A collection of functions for
- printing basic shapes.
- """
- CHAR = '*'
- def rectangle(height, width):
- """Prints a rectangle."""
- for row in range(height):
- for col in range(width):
- print(CHAR, end = '')
- def square(side):
- """prints a square."""
- rectangle(side, side)
- def triangle(height):
- """prints a right triangle. """
- for row in range(height):
- for col in range(1, row + 2):
- print(CHAR, end = '')
- print()
运行:
import shapes
shapes.rectangle(3, 8)
shapes.square(5)
结果却是:
************************
*************************
应该是
********
********
********
和
*****
*****
*****
*****
*****