Week 9 COMPSCI Quiz Questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What will be the output of the following Python code? def change(x = 0, y = 1): -----x = x + y -----y = y + 1 -----print(x, y) change(x = 0 , y = 1) change(x = 1 , y = 0) change(y = 1 , x = 0) change(y = 0 , x = 1)

1 2 1 1 1 2 1 1

Where is function defined in Python? - Module - Class - Another function - All of the mentioned

All of the mentioned

The function must return a value - T/F

False

What will be the output of the following Python code? def func(a, b=5, c=10): -----print('a is', a, 'and b is', b, 'and c is', c) func(3, 7) func(25, c = 24) func(c = 50, a = 100)

a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50

Which correctly defines two parameters x and y for a function definition: def calc_val( ): - calc_val (x y) : - calc_val (x; y) : - calc_val (x, y) : - calc_val (x : y) :

calc_val (x, y) :

What will be the output of the following Python code? def foo( i, x=[ ]): -----x.append(i) -----return x if __name__ == "__main__": -----for i in range( 3 ): ----------print( foo( i ) )

[0] [0, 1] [0, 1, 2]

What will be the output of the following Python code? def change(a, b): -----a = a + 1 -----b = b + 1 -----print(a, b) change( a = 1, b = 0 ) change( a = 0, b = 1 )

2 1 1 2

What will be the output of the following Python code? def printMax(a, b): -----if a > b: ----------print(a, 'is maximum') -----elif a == b: ----------print(a, 'is equal to', b) -----else: ----------print(b, 'is maximum') x = 3 y = 4 printMax( x+1, y)

4 is equal to 4

What will be the output of the following Python code? def foo( arg1, *args ): -----result = 0 -----for i in args: ----------result += i -----return result print( foo(1, 2, 3) ) print( foo(1, 2, 3, 4, 5) )

5 14

What will be the output of the following Python code? def foo( *args ): -----result = 0 -----for i in args: ----------result += i -----return result print( foo(1, 2, 3) ) print( foo(1, 2, 3, 4, 5) )

6 15

What will be the output of the following Python code? def power(x, y=2): -----result = 1 -----for i in range(y): ----------result = result * x -----return result print( power(3) ) print( power(3, 3) ) print( power(4) ) print( power(4, 3) )

9 27 16 64

Which are the advantages of functions in python? - Reducing duplication of code - Decomposing complex problems into simpler pieces - Improving clarity of the code - All of above

All of above

What are the two main types of functions in Python? - System function & Customer function - System function & User function - Built-in function & User defined function - Built-in function & Customer defined function

Built-in function & User defined function

What will be the output of the following Python code? def say(message, times = 1): -----print(message * times) say('Hello') say('World', 5)

Hello WorldWorldWorldWorldWorld

A function definition must be evaluated by the interpreter before the function can be called - T/F

True

A local variable is defined inside a function, while a global variable is defined outside any function - T/F

True

Given a function definition: def calc_val(a, b, c): and given variables i, j, and k, which are valid arguments in the call calc_val( )? - calc_val( i, j ) - calc_val( i, j + k ) - calc_val( k, i+ j, 99 ) - calc_val( i + j + k )

calc_val( k, i+ j, 99 )

Which keyword is used for function? - fun - function - def - define

def

What will be the output of the following Python code? x = 50 def func( ): -----global x -----print('x is', x) -----x = 2 -----print('Changed global x to', x) func( ) print('x is now', x)

x is 50 Changed global x to 2 x is now 2

What will be the output of the following Python code? x = 50 def func(x): -----print('x is', x) -----x = 2 -----print('Changed local x to', x) func(x) print('x is now', x)

x is 50 Changed local x to 2 x is now 50


Ensembles d'études connexes

Комп’ютерна лексикографія

View Set

FPCC- Pt id, confidentiality & Documentation

View Set

Procedures 1 Final Exam Study Questions

View Set

Domain 5: Identity and Access Management

View Set

Otitis Media, Cerebral Palsy, ADHD, Autism

View Set

Individual Taxation Acct 401, Ch 4 individual income tax, overview, dependents, and filing status

View Set

Module 5: Creating, Staining and Evaluating Peripheral Blood Films

View Set

Self Study Chapter 16 Multiple Choice

View Set