wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Function

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the output of the expression?

round(4.5676,2)?

a)

4.5

b)

4.6

c)

4.57

d)

4.56

2.

What is the output of the functions shown below?


divmod(10.5,5)

divmod(2.4,1.2)

a)

(2.00, 0.50)(2.00, 0.00)

b)

(2, 0.5)(2, 0)

c)

(2.0, 0.5)(2.0, 0.0)

d)

(2, 0.5)(2)

3.

What is the output of the function shown below?


hex(15)

a)

f

b)

0xF

c)

0Xf

d)

0xf

4.

What is the output?


d = {"john":40, "peter":45}

d["john"]

a)

40

b)

45

c)

“john”

d)

“peter”

5.

What is the output of the following piece of code?


a={1:"A",2:"B",3:"C"}

print(a.get(1,4))

a)

1

b)

A

c)

4

d)

Invalid syntax for get method

6.

What is the output of the following snippet of code?


total={}

def insert(items):

if items in total:

total[items] += 1

else:

total[items] = 1

insert('Apple')

insert('Ball')

insert('Apple')

print (len(total))

a)

3

b)

1

c)

2

d)

0

7.

What is called when a function is defined inside a class?

a)

Module

b)

Class

c)

Another function

d)

Method

8.

What is called when a function is defined inside a class?

a)

Module

b)

Class

c)

Another function

d)

Method

9.

The break command is used to stop the iteration process in the statement

a)

Perulangan for / while

b)

Percabangan if

c)

Perulangan for do / while

d)

d. Percabangan case of

10.

The built-in range () function is used to do the desired number of repetitions.

The following statement: >>> range (5,10) will produce output

a)

[5, 6, 7, 8, 9, 10]

b)

[6, 7, 8, 9, 10]

c)

[5, 6, 7, 8, 9]

d)

[6, 7, 8, 9]

11.

The raw_input function is used for..

a)

receive input data from the user through the keyboard with integer data types

b)

receive input data from the user through a keyboard with a string data type

c)

receive input data from the user through the keyboard with the float data type

d)

it's all true

12.

The command used to handle exceptions (handling exceptions) in Python is

a)

try catch

b)

try except

c)

case of

d)

try else

13.

Abbreviation for IDLE?

a)

Indigenous Development Lab

b)

Integrated Development Environment

c)

Integrated Developers Local Environment

d)

Indie Developers Environment

14.

Results from the Statment below..

a = [(x, y)

for x in [0, 3, 5]

for y in [5, 4, 0]

if x!=y]

print(a)

a)

[(0, 5), (0, 4), (3, 5), (3, 4), (3, 0), (5, 4), (5, 0)]

b)

[(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5)]

c)

[(0, 3, 5), (0, 4, 5)]

d)

[(0, 5), (0, 4), (0, 0), (3, 5), (3, 4), (3, 0), (5, 5), (5, 4), (5, 0)]

15.

The function used to find the desired information by matching the desired information with the available information is ...

a)

sorting

b)

search

c)

pivot

d)

filtering

16.

The results of the program below are ...

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

print(jumlah[-5])

a)

6

b)

5

c)

7

d)

2

17.

What will be the output after the following statement?

a = list (range (10, -10,3))

print (sum (a))

a)

0

b)

10

c)

18

d)

5

18.

The output from the script below is ...

def abc (world):

print ('hello% s'% world) abc ('Python')

a)

Hello world

b)

Hello Python

c)

All answers are missing due to an error

d)

Hello python world

19.

One of the most important programming concepts is the ability to group several lines of code into a unit that can be included in a program that is commonly called ...

a)

decomposition

b)

runtime system

c)

sub-programs

d)

typical error

20.

What is the default return value for a function that does not return any value explicitly?

a)

None

b)

int

c)

double

d)

public

21.

Which of the following items are present in the function header?

a)

function name

b)

function name and parameter list

c)

parameter list

d)

return value

22.

Which of the following keywords marks the beginning of the function block?

a)

fun

b)

define

c)

def

d)

function

23.

What is the name given to that area of memory, where the system stores the parameters and local variables of a function call?

a)

a heap

b)

storage area

c)

a stack

d)

an array

24.

Which of the following statements correctly represent the function body in the given code snippet?

def f(number):

# Missing function body

print(f(5))

a)

return “number”

b)

print(number)

c)

print(“number”)

d)

return number

25.

What is the output of the following code snippet?

def myfunc(text, num):

while num > 0:

print(text)

num = num - 1

myfunc('Hello', 4)

a)

HelloHelloHelloHelloHello

b)

HelloHelloHelloHello

c)

invalid call

d)

infinite loop

26.

Which of the following would you relate to a function call made with an argument passed as its parameter?

a)

function invocation

b)

pass by value

c)

pass by reference

d)

pass by name

27.

What is the output of the following code snippet?

num = 1

def func():

num = 3

print(num)

func()

print(num)

a)

1 3

b)

3 1

c)

The program has a runtime error because x is not defined.

d)

1 1

28.

Proses berpikir manusia umumnya melewati 2 tahap, adalah….

a)

Instrospection dan pshycological experiment

b)

Instrospection dan penalaran komputasi

c)

penalaran komputasi dan pshycological experiment

d)

smart robotica dan Acting Rationally

29.

Suatu fungsi dengan tipe ini akan memberikan kembalian/return berupa nilai bertipe….

a)

header

b)

integer

c)

library

d)

alphanumeric

30.

Sebuah sistem informasi yang memiliki intelegensia buatan (Artificial Intelegent) yang menyerupai intelegensia manusia disebut….

a)

Decision Support System

b)

Extra Sensory Project

c)

program ELIZA

d)

Expert System