7 ตัวอย่างโปรแกรม เริ่มต้น สำหรับ การเขียนโปรแกรม Python

ตัวอย่างที่ 1
=======

print("This is my first program")
print("This is the second line")

ตัวอย่างที่ 2
=======

print('value is {:.2f}'.format(5.39120))
print("{:,}".format(100000))
a=1
b=3
print("{0}-{1}".format(a,b))

ตัวอย่างที่ 3
=======

i = 1
while(i<10):
    print(i)
    i = i + 1

ตัวอย่างที่ 4
=======

rows =5
# outer loop
# if you want user to enter a number, uncomment the below line
# rows = int(input('Enter the number of rows'))
for i in range(rows+1):
# nested loop
    for j in range(i):
    # display number
        print(i, end='')
        # print "%(x)d" % {'x':i},
    # new line after each row
    print('')

ตัวอย่างที่ 5
=======

for i in range(1,13) :
    for j in range (2,7) :
        print ("{:2d} x{:2d}={:3d}".format(j,i,i*j),end='|')
    print('')


ตัวอย่างที่ 6
=======

'''
   1
  121
 12321
1234321
'''
def xprint(n):
    if (n==1):
        print(n,end = '')
    else:
        print (' ',end = '')

rows = 6
for j in range (1,rows+1):
    for i in range(rows-j):
        print(' ',end = '')
    for i in range(j):
        xprint (i+1)
    for i in range(j-2,-1,-1):
        xprint (i+1)

    print ('')
rows = 7
# outer loop
# if you want user to enter a number, uncomment the below line
rows = int(input('Enter the number of rows :'))
for i in range(rows):
# nested loop
    for j in range(rows):
    # display number
        print('O', end=' ')
    print('')

ตัวอย่างที่ 7
=======

rows = 7
# outer loop
# if you want user to enter a number, uncomment the below line
# rows = int(input('Enter the number of rows'))
for i in range(rows):
# nested loop
    for j in range(rows):
    # display number
        if (i==0) or (i==rows-1):
            print('O', end=' ')
        else:
            if (j==0) or (j==rows-1):
                print('O', end=' ')
            else:
                print(' ', end=' ')
    print('')

คำสำคัญ #วิชาวิทยาการคำนวณ #มัธยมศึกษา #โคดดิ้ง #การเขียนโปรแกรม #ไพธอน #python #เบื้องต้น #สอนพิเศษ #เรียนพิเศษ #รับรองผล #โรงเรียนประถม #โรงเรียนมัธยม #โรงเรียนอินเตอร์
สนใจเรียนพิเศษ สามารถอ่านต่อ ได้ที่ลิงค์นี้ครับ https://pornchaiscratch.blogspot.com/



Create Date : 02 พฤษภาคม 2564
Last Update : 26 พฤษภาคม 2564 16:27:45 น.
Counter : 739 Pageviews.

0 comments
ชื่อ : * blog นี้ comment ได้เฉพาะสมาชิก
Comment :
 *ส่วน comment ไม่สามารถใช้ javascript และ style sheet
 

thaiger_u
Location :
  

[ดู Profile ทั้งหมด]
 ฝากข้อความหลังไมค์
 Rss Feed
 Smember
 ผู้ติดตามบล็อก : 3 คน [?]



Dancinga
@ฟรี
โปรแกรมปฏิทิน 2564 - Free android app


@ รับสอน เขียนโปรแกรม Python ระดับมัธยมปลาย
พฤษภาคม 2564

 
 
 
 
 
 
1
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
27
29
30
31
 
 
All Blog