ตัวอย่างในการเขียนโค้ดภาษา Python เพื่อแสดงตัวเลข 1-9 เป็นรูปสามเหลี่ยม โดยฐานของรูปสามเหลี่ยมอยู่ด้านขวาและมุมบนหันไปด้านซ้าย
ตัวอย่างโค้ด Python
# -------------------------------------------------------#
# Author : Computer for Education #
# Author URI: https://www.computerforedu.com #
# Facebook : https://www.facebook.com/computerforedu #
# -------------------------------------------------------#
max_num = 9
i = 0
while i < max_num:
i += 1
for s in range(max_num-i):
print(" ", end='')
for n in range(1, i+1):
print(n, end='')
print("")
i = 0
while i <= max_num:
i += 1
for s in range(i):
print(" ", end='')
for n in range(1, (max_num+1)-i):
print(n, end='')
print("")
แสดงผล

