ACS Workshop (python)
มาทำโจทย์กันเถอะะะะะ (โดยพรี่ภูมิ)
Question 1
- เขียนโปรแกรมหาเส้นรอบรูปสี่เหลี่ยมผืนผ้า โดยกำหนดให้ ความกว้าง-ความยาว ของรูปสี่เหลี่ยมมา
| รูปเเบบ Input | 
|---|
| บรรทัดที่ 1 รับตัวเลขจำนวนเต็ม ความกว้าง | 
| บรรทัดที่ 2 รับตัวเลขจำนวนเต็ม ความยาว | 
| รูปเเบบ Output | 
|---|
| เส้นรอบรูปสี่เหลี่ยมผืนผ้า ตอบเป็นทศนิยม 2 ตําแหน่ง | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| 5 10 | 30 | 
| 25 50 | 150 | 
| 100 200 | 600 | 
def find_perimeter(width,length):
    perimeter = # your code here 
    return # your code here 
width= # Question2 input (line1)
length= # Question2 input (line2)
print(find_perimeter(width, length))
- hint สูตรคือ 2*(w+h)
Question 2
- เขียนโปรแกรมหาผักจากรายการที่ให้ไป
| รูปเเบบ Input | 
|---|
| list ที่เต็มไปด้วยผักและผลไม้ | 
| รูปเเบบ Output | 
|---|
| จำนวนของผักทั้งหมดใน list | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| ['Apple','Banana','Broccoli','Cucumber', 'Mango', 'Strawberry'] | 2 | 
| [] | 0 | 
| ['Apple', 'Banana', 'Orange'] | 0 | 
Question 3
- หาตัวเลขในรายการ (list) ที่น้อยที่สุด ให้มีรายการ (list) ที่มีตัวเลขเก็บอยู่
| รูปเเบบ Input | 
|---|
| list | 
| รูปเเบบ Output | 
|---|
| เลขที่น้อยที่สุด | 
| ข้อจำกัด | 
|---|
| ห้ามใช้ built in functions เช่น min() ,ตัวเลขเป็น integer | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| [17, 5, 9, 12, 2] | 2 | 
| [-1, 2, 5, 15, -2] | -2 | 
| [5, 0, 5, 6, 6, 4] | 0 | 
def find_minimum(numbers):
    min_num = numbers[0]
    for #your code here
        if #your code here
            #your code here
    return min_num
my_list = # Question3 input
minimum_number = find_minimum(my_list)
print(minimum_number) 
Question 4
- เขียนฟังก์ชันที่ย้อนกลับสตริง โดยสตริงอินพุตจะได้รับเป็นสตริงของอักขระ
| รูปเเบบ Input | 
|---|
| string | 
| รูปเเบบ Output | 
|---|
| string ที่ย้อนกลับแล้ว | 
| ข้อจำกัด | 
|---|
| ห้ามใช้ built in functions | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| etuCoSRU | URSoCute | 
| UwU | UwU | 
| gnaLginmmargorPsILMTH | HTMLIsProgrammingLang | 
| 700azwnl | lnwza007 | 
def reverseString(s):
    for i in ## your code here
        new_String = # your code here
    return # your code here
my_String =# Question4 input
my_String = reverseString(my_String)  
print(my_String)  
- นอกจาก for loop ยังมีวิธีอื่นที่สามารถทำ palindrome ได้
Question 5
- เขียนฟังก์ชันที่ตรวจสอบ x ว่าเป็นพาลินโดรมรึป่าว โดยกําหนด x เป็น int
| รูปเเบบ Input | 
|---|
| integer | 
| รูปเเบบ Output | 
|---|
| ส่งกลับค่า true ถ้าเป็นจริงและ false ถ้าเป็นเท็จ | 
| ข้อจำกัด | 
|---|
| ห้ามใช้ built in functions | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| mom | True | 
| kinnikinnik | True | 
| gigachad | False | 
| (()(()(( | True | 
| ฟหกหก | False | 
def isPalindrome(x):
    x_str = str(x)
   	return #your code here
print(isPalindrome(# Question5  input))
Question 6
- ใช้สัญลักษณ์ "#" เพื่อสร้างรูปเพรช
| รูปเเบบ Input | 
|---|
| integer | 
| รูปเเบบ Output | 
|---|
| รูปเพรช | 
| ข้อจำกัด | 
|---|
| ห้ามใช้ built in functions | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| 3 | # ### | 
| 7 | # ### ##### ############ ### # | 
| 1 | # | 
def draw_diamond(x):
		#your code here
print(draw_diamond(# Question6 input))
Question 7
- ตรวจสอบว่า สมาชิกใน nested list (`list2`) นั้นอยู่ใน `list1` หรือไม่
| รูปเเบบ Input | 
|---|
| list ทั้งหมด 2 list | 
| รูปเเบบ Output | 
|---|
| list | 
- ตัวอย่าง
| Input | Output | 
|---|---|
| [4, 7, 66, 2, 8, 12, -1] [[1, 2,3], [2, 4, 6, 7], [], [], [-1]] | [[2], [2, 4, 7], [], [], [-1]] | 
| [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13] [[12, 18, 23, 25, 45], [7, 11, 19, 28], [1, 5, 8, 18, 15]] | [[12], [7, 11], [1, 5, 8]] | 
| [[1, 2], 0, 1, -1, 2, [3, 4, 5], 6, 7] [[1, 2], [-1, 0], [[1,2]], [[3, 5]], 6] | [[1, 2], [-1, 0], [[1, 2]], [], [6]] | 
def intersection_nested_lists(list1, list2):
    result = []
    for l2 in list2:
        # Your code here
    return result
nums1 = [1, 2, 3, 4]
nums2 = [[1, 2], [3], [4]]
print(intersection_nested_lists(nums1, nums2))
