wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming

Total questions: 48

Worksheet time: 20mins

Name
Class
Date
1.

ข้อใดกล่าวไม่ถูกต้อง

a)

ไพธอน ไม่สามารถรันได้ใน Linux

b)

ไพธอน สามารถรันได้ทุกแพลตฟอร์ม

c)

 ไพธอน ไม่มีคำสั่ง Do while

d)

ไพธอน ใช้การแปลภาษาแบบอินเตอร์พรีเตอร์

2.

ข้อใดกล่าวไม่ถูกต้องเกี่ยวกับการแปลภาษาแบบ Compiler และ Interpreter

a)

Compiler เมื่อแปลภาษาแล้วจะได้ .exe (Execute File)

b)

Compiler ทำงานได้เร็วกว่า Interpreter หลายเท่าตัว เมื่อโปรแกรมมีขนาดใหญ่

c)

Interpreter จะแปลภาษาทีละบรรทัด

d)

Python เป็นภาษาแบบมี Compiler

3.

ข้อใดไฟล์นามสกุลของภาษาไพธอน

a)

.c

b)

.py

c)

 .python

d)

idle

4.

ข้อใดประกาศตัวแปรได้ถูกต้อง

a)

_def  = 1

b)

@score = 10.20

c)

elif = ‘’

d)

@try = [‘try’, ‘it’,’your’,’self’]

5.

ข้อใดประกาศตัวแปรได้ไม่ถูกต้อง

a)

x = [0,1,2]

b)

a=b=c=0

c)

 a,b = [10,20,50]

d)

a=[‘true’,{1,2,3,4}]

6.

ถ้าต้องการเขียนนิพจน์เพื่อคำนวณพื้นที่ สามเหลี่ยมหน้าจั่ว ซึ่งมีสูตรดังนี้

a4(4b2a2)\frac{a}{4}\sqrt{(}4b^2-a^2) กำหนดให้ a คือ ฐาน และ b คือ ด้านของ สามเหลี่ยม

a)

a/4*((4*(b**2)-(a**2))**(1/2)

b)

a%4*((4*(b**2)-(a**2))**(1/2)

c)

a/4*(sqrt(4*(b**2)-(a**2)),(1/2)

d)

 a/4*((4*(pow(2))-(a**2))**(1/2

7.

x = 10

x++

print(x)

a)

11

b)

10

c)

12

d)

Error

8.

ผลลัพธ์ของ

>>> 2*5**2*3

คือ ข้อใด

a)

300

b)

150

c)

600

d)

10610^6

9.

>>> x,y = 4,2

>>> x or y

a)

2

b)

3

c)

4

d)

6

10.

จงเติมชุดคำสั่งเพื่อให้โปรแกรมคิดพื้นที่สามเหลี่ยมทำงานได้อย่างสมบูรณ์

width = float(input("Width : "))

height = float(input("Height : "))

//เติมชุดคำสั่ง

print('='*20)

print("Area of Triangle : ",area)

a)

area = width*height

b)

area = (width*height)**0.5

c)

 area = 3.14*width*height

d)

 area = 0.5*width*height

11.

ถ้าต้องการแสดงผลด้วย f String จากชุดคำสั่งนี้ต้องเขียนอย่างไร

number = float(input("Number : "))

a)

print("Number is {number}")

b)

print(f"Number is {number}")

c)

print(f"Number is (number)")

d)

print(f"Number is [number]")

12.

จากชุดคำสั่งถ้ากรอก 2,3 จะได้ผลลัพธ์ว่าอย่างไร

x,y = float(input("x : "),input("y : "))

print(f'x and y : {x}{y}')

a)

Error

b)

x and y : 2 3

c)

 x and y : 2.0 3.0

d)

Undefind

13.

จากชุดคำสั่งจงเลือกชุดคำสั่งที่เหมาะสมในการรับค่า input

//เติมชุดคำสั่ง

//เติมชุดคำสั่ง

area = 0.5*width*height

print('='*20)

print("Area of Triangle : ",area)

a)

width = float(input("Width : "))

height = float(input("Height : "))

b)

width , height = float(input("Width : ")), float(input("Height : "))

c)

 ถูกทั้ง 1 และ 2

d)

ไม่มีข้อใดถูก

14.

การสร้างตัวแปรเพื่อรับค่าแบบนี้ถูกต้องหรือไม่ เพราะเหตุใด

x,y = float(input("x : "),input("y : "))

a)

ไม่ถูกเพราะต้องแปลง float ทีละค่า

b)

ถูกสามารถทำได้

c)

ไม่ถูกเพราะต้องรับ x และ y คนละบรรทัด

d)

 ผิดทุกข้อ

15.

 ข้อใดคือ Comments ในภาษา Python

a)

//comment

b)

 ‘comment

c)

#comment

d)

 /* comment */

16.

พิจารณาจาก Flowchart คือ การเขียน loop ในรูปแบบใด

a)

if

b)

while

c)

do while

d)

for loop

17.

พิจารณาจาก Flowchart คือ การเขียน loop ในรูปแบบใด

a)

if

b)

while

c)

do while

d)

for loop

18.

 พิจารณาจาก Flowchart คือ การเขียน loop ในรูปแบบใด

a)

if

b)

while

c)

do while

d)

for loop

19.

เขียนชุดคำสั่งเพิ่มเติมเพื่อให้ได้ผลลัพธ์ดังต่อไปนี้

10 9 8 7 6 5 4 3 2 1

a = [10,9,8,7,6,5,4,3,2,1]

for x in a :

#เติมชุดคำสั่ง

a)

print(x,end=" ")

b)

print(x,end=",")

c)

 print(x)

d)

print(end)

20.

ข้อใดประกาศตัวแปรไม่ถูกต้องตามหลักการ

a)

#myhome

b)

_myhome

c)

my-home

d)

ข้อ 1 และ 3 ผิด

21.

Editor ใดที่เป็น Tool ในการเขียนไพธอน

a)

 IDLE

b)

 Pycharm

c)

 Anaconda

d)

ถูกทุกข้อ

22.

ข้อใดเป็นการประกาศตัวแปรด้วยภาษาไพธอน

a)

Dim x as integer = 10

b)

public x integer = 10

c)

x= 10

d)

x = 10++

23.

ข้อใดเป็นการประกาศ function ในภาษาไพธอน

a)

public static void main()

b)

public function myFunction() as String

c)

def Myfunction()

d)

sub main()

24.

ข้อใดเป็นการแสดงผลหน้าจอด้วยภาษาไพธอน

a)

echo “Hello World”

b)

print(“Hello World”)

c)

printf(“Hello World”)

d)

console.writeln(“Hello World”)

25.

การติดตั้ง Package เพิ่มเติมในภาษา Python ใช้คำสั่งอะไร

a)

pip

b)

pup

c)

pap

d)

pop

26.

ข้อใดกล่าวไม่ถูกต้องเกี่ยวกับ Python

a)

Python สามารถนำไปใช้คำนวณทางคณิตศาสตร์ได้

b)

Python สามารถนำไปสร้าง Web ได้

c)

Python สามารถทำงานบนระบบปฎิบัติการ Rasberrypy

d)

Python ไม่สามารถเขียนแบบ OOP ได้

27.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

x = 10

def addX():

    global x

    x = 20

 

addX()

print(x)

a)

10

b)

20

c)

30

d)

40

28.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

def ShowMessage(msg = "Hello Welcome"):

    print("Hello " , msg)

ShowMessage("John")

ShowMessage()

a)

John

Hello  John

b)

Hello Welcome

c)

Hello  John

d)

Hello  John

Hello  Hello Welcome

29.

จงเติมชุดคำสั่งให้สามารถรับค่า function ได้

def LineOfCircle(r):

    line = 2 3.14 r

    return line

def CalAreaCircle(r):

    area = 3.14*(r**2)

    return area

def InfoSum(r):

    line = LineOfCircle(r)

    area = CalAreaCircle(r)

    return line,area

print("===Cal Info radius===")

r = float(input("Enter your radius : "))

//เติมชุดคำสั่ง

print("Line of Circle : ", line)

print("Area of Circle : ", area)

a)

area = InfoSum(r)

b)

line = InfoSum(r)

c)

 InfoSum(line,area)

d)

 line,area = InfoSum(r)

30.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

cars = {

    "brand":"Toyata",

    "color": ['gray','red','white'] 

    }

cars["color"][0] = 'Yellow'

for x,y in cars.keys(),cars.items():

    print(x,y)

a)

 Error

b)

brand color

('brand', 'Toyata') ('color', ['Yellow', 'red', 'white'])

c)

brand color

('brand', 'Toyata') ('color', ['gray', 'red', 'white'])

d)

brand color

('brand', 'Toyata') ('color', [ 'red', 'white'])

31.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

data = {

    "air":67,

    "air":68,

    "air":69

    }

print(data)

a)

 {'air': 69}

b)

{'air': 67}

c)

{'air': 68}

d)

 Error เพราะ key ซ้ำกัน

32.

จากตารางเปรียบเทียบทั้ง 3 ดังกล่าวจงเลือกให้สอดคล้องกับข้อมูลของ Set

a)

changeable, duplicate members

b)

unchangeable, No duplicate members

c)

None, None

d)

unchangeable, duplicate members

33.

 จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

list(range(1,20,3))

a)

 [1, 4, 7, 10, 13, 16, 19]

b)

 [1, 6, 11, 16]

c)

 [2,4,6,8,10]

d)

[1,3,5,7,9]

34.

จากชุดคำสั่ง

data = [1,[2,[3]]]

print('Access Data')

print('-'*10)

ถ้าต้องการเข้าถึงให้ได้ผลลัพธ์ต้องเขียนชุดคำสั่งว่าอย่างไร

Access Data

----------

3

a)

 print(data[2])

b)

 print(data[1][2])

c)

print(data[1][1][0])

d)

 print(data[1][1][1])

35.

 จากชุดคำสั่งผลลัพธ์คืออะไร

point = [10,20,30,40,50,100,150]

y = [x for x in point if x > 30 in point]

print(y)

a)

[10,20,30,40]

b)

[30,100,150]

c)

[20,40,100]

d)

[40, 50, 100, 150]

36.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

seta = set("a","b","c")

print(seta)

a)

 Error

b)

(“a”,”b”,”c”)

c)

[“a”,”b”,”c”]

d)

 {“a”,”b”,”c”}

37.

จากชุดคำสั่งผลลัพธ์คืออะไร

seta = {"a","b","c"}

lst = [1,2,3,4,5,6,7,8]

seta.update(lst)

print(seta)

a)

Error เพราะ list update กับ Set ไม่ได้

b)

{1, 2, 3, 4, 5, 6, 7, 8, 'c', 'b', 'a'}

c)

[1, 2, 3, 4, 5, 6, 7, 8, 'c', 'b', 'a']

d)

(1, 2, 3, 4, 5, 6, 7, 8, 'c', 'b', 'a')

38.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

seta = {"cat","dog","bird","rat"}

a = seta.pop()

print(a)

print(seta)

a)

dog

{'rat', bird, 'cat'}

b)

cat

{'rat', 'dog', 'bird'}

c)

bird

{'rat', 'dog'}

d)

bird

{'rat', 'dog', 'cat'}

39.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

a = ("apple",)

print(type(a))

a)

Error เนื่องจาก ,

b)

<class 'tuple'>

c)

 <class 'list'>

d)

<class 'Array'>

40.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

a = tuple(("apple","cherry","banana"))

print(type(a))

a)

Error เนื่องจากใส่วงเล็บเกิน

b)

<class 'tuple'>

c)

<class 'list'>

d)

<class 'Array'>

41.

จากชุดคำสั่งจะแสดงผลลัพธ์ว่าอย่างไร

a = ("a","b","c")

x = list(a)

 

x[0] = "1"

a = tuple(x)

print(a)

a)

('1', 'b', 'c')

b)

 ['1', 'b', 'c']

c)

{'1', 'b', 'c'}

d)

 ['1'], ['b'],[ 'c']

42.

จากไฟล์ importFor.py ที่ชุดคำสั่งดังนี้

def SayHello():

    print("Hello"*3)

def SayGoodBye():

    print("Say Good bye !!!")

เมื่อสร้างไฟล์ใหม่แล้วเขียนชุดคำสั่งดังนี้ จะได้ผลลัพธ์ว่าอย่างไร

from importFor import SayHello

print(SayHello())

a)

HelloHelloHello

None

b)

HelloHelloHello

c)

None

d)

Hello

43.

จากชุดคำสั่งจะได้ผลลัพธ์อย่างไร

def main():

    print("This is main!!!")

if name =="__main__":

    main()

a)

This is main!!!

b)

Error

c)

โปรแกรมหยุดทำงาน

d)

โปรแกรมว่างเปล่าไม่ได้มีอะไรแสดงผล

44.

จากชุดคำสั่งถ้าต้องการเติมชุดคำสั่งเพื่อตรวจเชคว่ารับค่าเป็นตัวเลขหรือไม่ จะเขียนชุดคำสั่งว่าอย่างไร
try:

    //เติมชุดคำสั่ง

except ValueError:

    print("Wrong Number")

a)

 x = int(input("Please Enter Your Integer : "))

b)

 x = input("Please Enter Your Integer : ")

c)

x = float(input("Please Enter Your Integer : "))

d)

 x = map(input("Please Enter Your Integer : "))

45.

จากชุดคำสั่งเมื่อกรอกข้อมูลเป็นเลข 2 จะได้ผลลัพธ์อย่างไร

try:

    x = input("Enter your float : ")

    if type(x) == float:

        print("Ok float")

    elif type(x) == int:

        print("OK integer")

    elif type(x)==str:

        print("Ok String")

except ValueError:

    print("Wrong Input")

finally:

    print("Done...")

a)

Error

b)

Enter your float : 2

Ok Integer

Done...

c)

 Wrong Input

Done...

d)

Enter your float : 2

Ok String

Done...

46.

จากไฟล์ doc.txt ซึ่งมีเนื้อหาภายในดังนี้

Air Times 3  !!!!!

Air Times 2  !!!!!

Air Times 1  !!!!!

Boom!!!!

ผลลัพธ์จากชุดคำสั่งจะเป็นอย่างไร

f = open('doc.txt')

cnt = 0

for x in f:

    cnt = cnt +1

    if(cnt==3):

        print(x)

f.close()

a)

Air Times 3  !!!!!

b)

 Air Times 2  !!!!!

c)

 Air Times 1  !!!!!

d)

 Boom!!!!

47.

จากไฟล์ doc.txt

Air Times 3  !!!!!

Air Times 2  !!!!!

Air Times 1  !!!!!

Boom!!!!

ผลลัพธ์จากชุดคำสั่งจะเป็นอย่างไร

f = open('doc.txt','r')

print(f.read())

a)

Air Times 3  !!!!! Air Times 2  !!!!! Air Times 1  !!!!! Boom!!!!

b)

Air Times 3  !!!!!

Air Times 2  !!!!!

Air Times 1  !!!!!

Boom!!!!

c)

Air Times 1  !!!!!

Air Times 2  !!!!!

Air Times 3  !!!!!

d)

undefind

48.

จากไฟล์ doc.txt

Air Times 3  !!!!!

Air Times 2  !!!!!

Air Times 1  !!!!!

Boom!!!!

ผลลัพธ์จากชุดคำสั่งจะเป็นอย่างไร

f = open('doc.txt','r')

c = f.readlines()

print(c[0:2])

a)

 Air Times 1  !!!!!

b)

Boom!!!

c)

('Air Times 3  !!!!!\n', 'Air Times 2  !!!!!\n')

d)

 ['Air Times 3  !!!!!\n', 'Air Times 2  !!!!!\n']