ตัวอย่างโค้ดภาษา Python วนรับค่าตัวเลขทศนิยม จำนวน 5 ค่า จากนั้นนำค่าที่ได้มาแสดงผลในแต่ละรายการทั้งหมด 5 ครั้ง แล้วนำค่าในรับเข้ามามารวมกันและแสดงเป็นผลรวม
ตัวอย่างโค้ด
# -------------------------------------------------------#
# Author : Computer for Education #
# Author URI: https://www.computerforedu.com #
# Facebook : https://www.facebook.com/computerforedu #
# -------------------------------------------------------#
ls = []
total = 0.0
for i in range(5):
f = float(input("กรอกตัวเลขทศนิยม ครั้งที่ {0:d} : ".format(i+1)))
ls.append(f)
total += f
print("")
for i in range(5):
print("แสดงผลตัวเลขทศนิยม ครั้งที่ {0:d} : {1:.2f}".format(i+1, ls[i]))
print("\nผลรวมทั้งหมด คือ {0:.2f}".format(total))
แสดงผล

