Midterm Python

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/43

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

44 Terms

1
New cards

What is the correct sequence of steps for interacting with a computer program?
a. Execute, type command, wait for response
b. Type command, wait for response, execute
c. Wait for response, type command, execute

d. Type command, execute, wait for response

d. Type command, execute, wait for response

2
New cards

Which of the following functions can be used to check inheritance in Python?

a. isinstance()
b. isinherit()
c. issuper()

d. issubclass()

d. issubclass()

3
New cards

How does Python support multiple inheritance?

a. By adding more methods to a single base class
b. By creating new classes from existing classe
c. By overriding methods in parent classes

d. By adding more base classes into the parentheses

d. By adding more base classes into the parentheses

4
New cards

In Python, what is a package?
a. A set of built-in modules that come pre-installed with Python

b. A collection of unrelated modules bundled together for convenience

c. A type of file format used to distribute Python code

d. A bunch of related modules organized into sub-packages, sub- sub-packages and more

d. A bunch of related modules organized into sub-packages, sub- sub-packages and more

5
New cards

What are the five basic states of a process?

a. Initial, active, paused, suspended, complete

b. Active, standby, pending, scheduled, finished

c. Creating, executing, pausing, stopping, closing

d. New, ready, running, waiting, terminated

d. New, ready, running, waiting, terminated

6
New cards

What components are typically included in the execution state of a process?

a. Keyboard input buffer, network socket connections, and display output buffer

b. System clock rate, CPU temperature, and fan speed

c. Processor state, file descriptors, and memory allocation

d. Hard disk storage capacity, disk fragmentation status, and read/write speeds

c. Processor state, file descriptors, and memory allocation

7
New cards

Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom

c) Guido van Rossum

8
New cards

All keywords in Python are in _________
a) Capitalized

b) lower case
c) UPPER CASE

d) None of the mentioned

d) None of the mentioned

9
New cards

Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned

a) Indentation

10
New cards

10. Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*

b) #

11
New cards

11. What will be the output of the following Python code?

i = 1
while True:
    if i%3 == 0:
        break
    print(i)
    i + = 1

a) 1 2 3
b) error
c) 1 2
d) none of the mentioned

b) error

(i += 1)

12
New cards

Which of the following functions can help us to find the version of python that we are currently working on?
a) sys.version(1)
b) sys.version(0)
c) sys.version()
d) sys.version

d) sys.version

13
New cards

Python supports the creation of anonymous functions at runtime, using a construct called __________
a) pi
b) anonymous
c) lambda
d) none of the mentioned

c) lambda

(lambda = anonymous)

14
New cards

Which of the following is true for variable names in Python?
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned

b) unlimited length

15
New cards

What are the values of the following Python expressions?

2**(3**2)
(2**3)**2
2**3**2

a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64

a) 512, 64, 512

16
New cards

Which of the following is the truncation division operator in Python?
a) |
b) //
c) /
d) %

b) //

17
New cards

Which of the following is the use of id() function in python?
a) Every object doesn’t have a unique id
b) Id returns the identity of the object
c) All of the mentioned
d) None of the mentioned

b) Id returns the identity of the object

18
New cards

What will be the output of the following Python expression if x = 56.236?

print("%.2f" % x)

a) 56.236
b) 56.23
c) 56.0000
d) 56.24

d) 56.24

19
New cards

What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the built-in namespace, then the global namespace and finally the local namespace
b) Python first searches the built-in namespace, then the local namespace and finally the global namespace
c) Python first searches the local namespace, then the global namespace and finally the built-in namespace
d) Python first searches the global namespace, then the local namespace and finally the built-in namespace

c) Python first searches the local namespace, then the global namespace and finally the built-in namespace

local-global-buildin

20
New cards

Which one of the following is not a keyword in Python language?
a) pass
b) eval
c) assert
d) nonlocal

b) eval

21
New cards

What will be the output of the following Python code?

class tester:
    def __init__(self, id):
        self.id = str(id)
        id = "224"

temp = tester(12)
print(temp.id)

a) 12
b) 224
c) None
d) Error

a) 12

id = 224 is local

22
New cards

Which module in the python standard library parses options received from the command line?
a) getarg
b) getopt
c) main
d) os

b) getopt

23
New cards

What will be the output of the following Python program?

z = set('abc')
z.add('san')
z.update(set(['p', 'q']))
print(z)

a) {'a', 'c', 'c', 'p', 'q', 's', 'a', 'n'}
b) {'abc', 'p', 'q', 'san'}
c) {'a', 'b', 'c', 'p', 'q', 'san'}
d) {'a', 'b', 'c', ['p', 'q'], 'san'}

c) {'a', 'b', 'c', 'p', 'q', 'san'}

24
New cards

Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()

d) set()

25
New cards

What is the return type of function id?

a) int

b) float

c) bool

d) dict

a) int

26
New cards

What is output of print(math.pow(3, 2))?
a) 9.0

b) None

c) 9

d) None of the mentioned

a) 9.0

27
New cards

Which of the following is invalid?

a) a = 1

b) _a = 1

c) —str— = 1

d) none of the mentioned

d) none of the mentioned

28
New cards

Which is the correct operator for power(xy)?

a) X^y

b) X**y

c) X^^y

d) None of the mentioned

b) X**y

29
New cards

What error occurs when you execute the following Python code snippet?

apple = mango

a) SyntaxError

b) NameError

c) ValueError

d) TypeError

b) NameError

30
New cards

What will be the output of the following Python code snippet?

def ex(a):
    a = a + '2'
    a = a*2
    return a
print(ex("hello"))

a) indentation Error

b) cannot perform mathematical operation on strings

c) hello2

d) hello2hello2

d) hello2hello2

31
New cards

Which of the following results in a SyntaxError?

a) ‘”Once upon a time…”, she said.’

b) “He said, ‘Yes!'”

c) ‘3\’

d) ”’That’s okay”’

c) ‘3\’

32
New cards

What is the return value of trunc()?

a) int

b) bool

c) float

d) None

a) int

33
New cards

What is the output of print 0.1 + 0.2 == 0.3?

a) True

b) False

c) Machine dependent

d) Error

b) False

(0.1 + 0.2 = 0.3000000000000004)

34
New cards

Which of the following is not a complex number?

a) k = 2 + 3j

b) k = complex(2, 3)

c) k = 2 + 3l

d) k = 2 + 3J

c) k = 2 + 3l

(j not i)

35
New cards

What is the type of inf?

a) Boolean

b) Integer

c) Float

d) Complex

c) Float

36
New cards

What does ~4 evaluate to?

a) -5

b) -4

c) -3

d) +3

a) -5

[ ~x == -(x+1) ]

37
New cards

Which of the following is incorrect?

a) x = 30963

b) x = 0x4f5

c) x = 19023

d) x = 03964

d) x = 03964

[cannot leading 0]

38
New cards

What is the result of cmp(3, 1)?

a) 1

b) 0

c) True

d) False

a) 1

[ cmp(x,y)

= 1 if x>y

= 0 if x==y

= -1 if x<y ]

39
New cards

Which of the following is incorrect?

a) float(‘inf’)

b) float(‘nan’)

c) float(’56’+’78’)

d) float(’12+34′)

d) float(’12+34′)

40
New cards

If a function doesn’t have a return statement, which of the following does the function return?

a) int

b) null

c) None

d) An exception is thrown without the return statement

c) None

41
New cards

How are keyword arguments specified in the function heading?

a) one-star followed by a valid identifier

b) one underscore followed by a valid identifier

c) two stars followed by a valid identifier

d) two underscores followed by a valid identifier

42
New cards

Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

a) Raw_input & Input

b) Input & Scan

c) Scan & Scanner

d) Scanner

a) Raw_input & Input

43
New cards

What is the primary function of a Process Control Block (PCB) in an operating system?
a) The PCB is used to manage network connections between processes
b) The PCB is used to store configuration settings for the operating system
c) The PCB is used to allocate memory to device drivers in the system
d) The PCB is used to store and manage information about a process, including its state, priority, allocated resources, and other relevant details

d) The PCB is used to store and manage information about a process, including its state, priority, allocated resources, and other relevant details

44
New cards

Which function is used to execute a shell command from within a program in an operating system?
a) popen()
b) fork()
c) exec()
d) system()

d) system()