L.1 algorithm design
L.2 boolean value
L.3 create variables
L.4 calculate and show
L.5 apply boolean
L.6 While loop concept
L.7 start code while
L.8 while continue
L.9 elif concepts
L.10 elif ex2.5 busfare
L.11 geometry shapes
L.12 circle area
L.13 triangle & rectangle
L.14 prevent wrong input
L.15 show shape name
L.16 draw shapes
L.17 exercise 2.1 q.3 variables
L.18 exercise 2.1 q.3 input
L.19 exercise 2.1 q.3 process & output
L.20 builtin Function ex.2.7
L.21 create custom Function ex.2.8
L.22 ex.2.9 function multiple parameters
L.23 ex.2.10 function draw square
L.24 ex.2.10 function draw triangle
L.25 ex.2.10 function draw house
L.26 ex.2.11 return function 1
L.27 ex.2.11 return function 2
2.2 ตัวดำเนินการบูเลี่ยน and, or, not
age = 12 --> print (age>13 and age<19)
age>13 or age<19
not age>13
2.3 ค่าโดยสารหมู่คณะ ค่าโดยสาร 10 บ./คน เด็กต่ำกว่า 3 ฟรี, อายุ 60 ขึ้น ครึ่งราคา, ไม่เกิน 30 คนและรวม 200 บาทขึ้นไป ลดเพิ่ม 10%
2.4 while
x int(input
sum, max, n = 0
while x>0:
n += 1
sum += x
if (x>max):
max=x
x input ใส่เลข หรือ 0 grnjvsp6f
if n>0:
print (sum, max)
EX 2.5 (p.60) if / elif / else
fare = 6.5
age = int(input(
if age >= 60
fare =
elif age <= 3
fare =
else
fare =
print ("ค่าโดยสารของท่านคือ",fare)
==========================
EX 2.6 หาพื้นที่ วงกลม สามเหลี่ยม สี่เหลี่ยม
from math import pi
shape = input ( 'หาพื้นที่วงกลม C, t, r
if shape == 'c':
r = float (input(" key radius: ")
area = pi * r * r
elif ...:
else :
print("พื้นที่รูป , area, ตารางหน่วย"
==========================
EX 2.7
age = int(input( " How old are
you? :"))
if age >= 60:
fare = 3.25
elif age <= 3:
fare = 0
else:
fare = 6.50
print ("ค่าโดยสารของท่านคือ" , fare)
Ex 2.8 ฟังก์ชั่น hello1 ( )
#วิธีสร้างฟังก์ชั่น
def hello1(name):
print ("สวัสดี", name)
#เรียกใช้ฟังก์ชั่น
hello1 ('Peter')