1.ใส่ชื่อตัวแปรไม่ตรงกัน เช่น
def setup():
string = 'thailand'
lasttring = 'and' <<<<<<<<<<<<< ผิดตรงนี้ไงครับ laststring สิ ไม่ใช่ lasttring อิอิ
assert my_endswith(string, laststring) == True
setup()
วิธีแก้คือ แก้ไขชื่อให้ตรงกัน โปรแกรมเราก็จะสามารถรันได้ตามปกติ
2.ลืมส่งค่ากลับ เช่น
def my_startswith(string, firststring):
result = False
i = 0
if (len(string) > len(firststring)):
while (i < len(firststring)):
if (string[i] == firststring[i]):
result = True
else:
result = False
i = i+1
โปรแกรมก็ไม่สามารถรู้ผลสิ วิธีแก้คือ ใส่ return result ไปซะ ดังนี้
def my_startswith(string, firststring):
result = False
i = 0
if (len(string) > len(firststring)):
while (i < len(firststring)):
if (string[i] == firststring[i]):
result = True
else:
result = False
i = i+1
return result <<<<<<<<<<<<<<<<<<<<<< นี้ไง ใส่มาแล้ว แค่นี้เราก็จะสามารถรันโปรแกรมได้ตามปกติ
3.ลืมอัพเดทค่า
def my_strip(string, strip):
wordwithoutstrip = ''
i = 0
while (i < len(string)):
if (i < len(strip)):
wordwithoutstrip = wordwithoutstrip + string[i]
return wordwithoutstrip แบบนี้เราก็จะรันโปรแกรมไม่ได้นะครับ วิธีแก้คือ
def my_strip(string, strip):
wordwithoutstrip = ''
i = 0
while (i < len(string)):
if (i < len(strip)):
wordwithoutstrip = wordwithoutstrip + string[i]
i = i+1 <<<<<<<<<<<<<<<<<<< ก็อัพเดทค่ามันซะสิ เราก็จะสามารถรันโปรแกรมได้ตามปกติ
return wordwithoutstrip
ไม่มีความคิดเห็น:
แสดงความคิดเห็น