ตอนจบของสามก๊กสอนว่า ความดีเท่านั้นที่จะยังคงอยู่ตลอดไป
|
|||
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/ |
thaiger_u
Rss Feed Smember ผู้ติดตามบล็อก : 3 คน [?] @ฟรี โปรแกรมปฏิทิน 2564 - Free android app @ รับสอน เขียนโปรแกรม Python ระดับมัธยมปลาย Group Blog All Blog
|
||
Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved. |