ผลต่างระหว่างรุ่นของ "Prg2/recur practice"
ไปยังการนำทาง
ไปยังการค้นหา
Jittat (คุย | มีส่วนร่วม) |
Jittat (คุย | มีส่วนร่วม) |
||
แถว 41: | แถว 41: | ||
== mymerge == | == mymerge == | ||
+ | <syntaxhighlight lang="python"> | ||
+ | def mymerge(lst1, lst2): | ||
+ | """ | ||
+ | >>> mymerge([1,2,3],[]) | ||
+ | [1, 2, 3] | ||
+ | >>> mymerge([],[4,5,6]) | ||
+ | [4, 5, 6] | ||
+ | >>> mymerge([1,2,5,6,10],[2,3,4,5,8,9,12]) | ||
+ | [1, 2, 2, 3, 4, 5, 5, 6, 8, 9, 10, 12] | ||
+ | >>> mymerge([6],[2,3,4,5,8,9,12]) | ||
+ | [2, 3, 4, 5, 6, 8, 9, 12] | ||
+ | >>> mymerge([2,3,4,5,8,9,12],[7]) | ||
+ | [2, 3, 4, 5, 7, 8, 9, 12] | ||
+ | """ | ||
+ | return [] | ||
+ | </syntaxhighlight> |
รุ่นแก้ไขเมื่อ 07:36, 28 กุมภาพันธ์ 2562
mysum
def mysum(lst):
"""
>>> mysum([])
0
>>> mysum([10])
10
>>> mysum([10, 20, 30])
60
>>> mysum([1,0,-10,5,9])
5
"""
return 0
To test, call
python -m doctest mysum.py
mysum
def mymax(lst):
"""
>>> mymax([1])
1
>>> mymax([-10, -30, -50])
-10
>>> mymax([1, 2, 3, -10])
3
>>> mymax([5000,6,7,100,2])
5000
>>> mymax([5,6,7,100,2])
100
>>> mymax([5,6,7,100,200])
200
"""
return 0
mymerge
def mymerge(lst1, lst2):
"""
>>> mymerge([1,2,3],[])
[1, 2, 3]
>>> mymerge([],[4,5,6])
[4, 5, 6]
>>> mymerge([1,2,5,6,10],[2,3,4,5,8,9,12])
[1, 2, 2, 3, 4, 5, 5, 6, 8, 9, 10, 12]
>>> mymerge([6],[2,3,4,5,8,9,12])
[2, 3, 4, 5, 6, 8, 9, 12]
>>> mymerge([2,3,4,5,8,9,12],[7])
[2, 3, 4, 5, 7, 8, 9, 12]
"""
return []