Quiz
Week 11 - Quiz
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (15)
1
[Python] Consider the following function definition. Which one is correct output?
>>> def place_stuff(x = 10, y = 20, z = 30):
return x, y, z
>>> place_stuff()- A(10, 20, 30)
- B{10, 20, 30}
- C[1, 2, 3]
- D10
- E(1, 2, 3)
- FAn error message
2
[Python] The ___ module allows you to store an object in a file in a standard format for later use by the same or a different program.- AIOlib
- BSTDlib
- Cpickle
- Dmelon
- EPyLib
3[Python] Which one of the following is correct given the code segment below?
>>> A = ['a', 'b', 'c']
>>> B = ['1', '2', '3']
>>> all = [x + y for x in A for y in B]
>>> print all- A['a', 'b', 'c', '1', '2', '3']
- B['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
- C['a1', 'b2', 'c3']
- D['1a', '1b', '1c', '2a', '2b', '2c', '3a', '3b', '3c']
- E['1a', '2a', '3a', '1b', '2b', '3b', '1c', '2c', '3c']
4[Python] Consider the following code segment. Which one of the following statements is correct?
import random
random.sample(range(10), 10)- AThis will generate a range of numbers from 1 to 10, listed in random order.
- BThis will generate a range of numbers from 0 to 9, listed in random order
- CThis will generate 10 random numbers.
- DThis will generate a range of random numbers from -10 to 10.
- EAn error message
5
[Python] Consider the following function definition. Which one is correct output?
>>> def place_stuff(x = 10, y = 20, z = 30):
return x, y, z
>>> place_stuff(1,2,3)- A(1, 2, 3)
- B{1, 2, 3}
- C[1, 2, 3]
- D1
- E1, 2, 3
- FAn error message
6
[Python] Consider a file "gm.py" listed below. Which of the following is incorrect to run this python file?
#!/usr/bin/local/python
print 'Good morning!'- A./gm.py
- Bpython gm.py
- Cpython < gm.py
- Dcat gm.py | python
- Eecho gm.py | python
7
[Python] One of the simplest re (for regular expression) methods is ___ returns a list that holds matches with a regular expression over a string- Aindex
- Bmatch
- Cfindall
- Dsearchall
- Eglobal
8
[Python] Which one of the following examples uses a list comprehension to fill a list with powers of 2.- A[2**x for x : range(1, 10)]
- B[x*2 in range(1, 10)]
- C[x*x for x :: range(1, 10)]
- D[2**x for x in range(1, 10)]
- E[2**x for x in random.range(1, 10)]
9[Python] Which one of the code segments makes each element of "items" to be squared, and printed?
- Afor x in items : print(x*x)
- Bfor x in items { print(x*x) }
- Cfor items AS x : print(x*x)
- Dfor x : items => print(x*x)
- Efor (x in items) print(x*x)
10
[Python] Which one of the following statements is incorrect?- APython supports Lambda functions.
- BLambda functions in Python might not be bound to a name.
- CLambda functions are referred to as anonymous functions.
- DLambda functions are more flexible than other functions because they can use an extensive functional features.
- EIn its most basic form, Lambda is another syntax for defining a function.
11
[Python] Which one of the following builtin function is to apply a function (first argument) to each of the rest of the parameters?- Amap
- Blamdba
- Cclosure
- Dappend
- Efunction
12[Python] Consider the following code segment. Which one of the following statements is correct?
map(lambda x: x * 2, [1, 3, 4])- AThis function has a syntax error
- BThis function will double each element of [1, 3, 4]
- CThis function, when called, will pick up the first, third, and fourth elements of the argument (a list) to be doubled
- DThis function requires two arguments to run correctly.
- EThis function requires an external library to run correctly.
13
[Python] After a file is opened for read with a variable f (a file handle), which one of the following code segment is correct to read each line using for loop?- Afor line as f.readlines( ) : print(line)
- Bfor f.readlines( ) AS line : print(line)
- Cfor line in readlines( ) : print(line)
- Dfor line in f.readlines( ) : print(line)
- Efor line from f.readlines : print(line)
14
[Python] Which one of the following is correct for this code segment run?
>>> my_list = [x + 10 for x in range(3)]
>>> my_list- A[1, 2, 3]
- B[10, 20, 30]
- C[10, 11, 12]
- D[10, 2, 3]
- E[1, 2, 13]
15[Python] Which one of the following statements opens a file and returns a file object called a file handle
- Aopen('test_file', 'read')
- Bopenfile('r', 'test_file')
- Copen('test_file', 'r')
- Dopen(file, 'test_file', 'read')
- Eofile('test_file', 'r')
Information
- Description
- test 2 UNIX Quiz on Week 11 - Quiz, created by hassy saade on 19/11/2018.
- Author
- hassy saade
- Language
- English
- Views
- 24
- Tags
- Rating
- No ratings yet Rate this quiz