ISU IT170 Exam 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What's the result of str(float(10)) in Python shell?

'10.0'

What's the result of the operation "3" * 3 in Python shell?

'333'

def myFunc(n): n += 1 return n n = 10 myFunc(n) print("n = " + str(n)) What's the output of the program above?

10

What is the result of the following? >>>aList=['This','is','a','very','good','idea'] >>>print(aList.index('very'))

3

What's output of the following? import re haRegex = re.compile(r'(Ha){1,3}') mo1 = haRegex.search('HaHaHa') print(mo1.group()) A. HaHaHa B. HaHa C. Ha D. Ha HaHa

A

What's the output of the following? import re msg = 'My lucky number is 777.' msgRegex = re.compile(r'\d') result = msgRegex.findall(msg[10:100]) print(result) A. ['7', '7', '7'] B. 777 C. 7 D. error

A

What's the type for the variable "var" in the following code (assume the code works fine): var = os.listdir('C:\\Windows\\System32') A. list B. tuple C. string D. int

A

Which module in Python supports regular expressions? A. re B. regex C. pyre D. none of the above

A

Choose all legitimate python variables from the following: A. _abc B. 3a C. ab_c D. ab c E. a*b

A and C, no numbers, spaces, or special chars

Choose all Python command that can print: I'm a student A. print("I'm a student") B. print("I\'m a student") C. print('I\'m a student') D. print('I'm a student')

A, B, C

>>> spam = ['cat', 'dog', 'bat'] >>> spam.insert(1, 'chicken') >>> spam The result is:

A. ['cat', 'chicken', 'dog', 'bat']

Select all binary files from the following: A. abc.doc B. abc.py C. abc.pdf D. abc.txt

A. abc.doc C. abc.pdf

>>> 'howdy' in ['hello', 'hi', 'howdy', 'heyas'] - The result is:

True

In OOP, a class creates a new type where objects are instances of the class. A. True B. False

True

True or False A list can also contain other lists.

True

True or False A list is a mutable data type.

True

True or False A raw string completely ignores all escape characters and prints any backslash that appears in the string.

True

True or False In Python, you need to define a function first before you can use it.

True

True or False Tuples cannot have their values modified, appended, or removed.

True

True or False Unlike lists, items in dictionaries are unordered.

True

True or False range(10), range(0, 10), and range(0, 10, 1) used in a for loop all do the same thing.

True

True or false In Python, a data type is a category for values, and every value belongs to exactly one data type.

True

>>> [1, 2] * 2 - Enter the code above into a Python shell, the result is:

[1, 2, 1, 2]

>>> aList = [1, 2, 3, 4] >>> del aList[2] >>> aList

[1, 2, 4]

aList = [1, 2, 3, 4] what is the return value of aList[1: -1]?

[2, 3]

What is the data type of the variable a? >>> a = 'MyABCnameABCisABCSimon'.split('ABC')

list

What's the result of the operation 11%3 in Python shell?

2

>>> a = ','.join(['a', 'b', 'c']) What is the result of len(a)?

5

aList = [[1,2,3,4,5], [10, 20, 30, 40, 50]]. Then aList[1][4] returns______.

50

>>> m =[2, 4, 6, 8, 10] >>> m[int(int('3' * 2) // 12)] The result is:

6

There are two ways to specify a file path. an absolute path, which always begins with C:\, and a relative path, which is relative to the program's current working directory. A. True B. False

Answer Key: False Feedback: An absolute path, which always begins with the root folder.

A single period ("dot") for a folder name is shorthand for "this directory." Two periods ("dot-dot") means "the root folder." A. True B. False

Answer Key: False Feedback: Two periods ("dot-dot") means "the parent folder."

In Python, the read() method is to get all content from a file; the readlines() method is to get one line from a file. A. True B. False

Answer Key: False Feedback: the readlines() method is to get a list of string values from the file.

What does the __init__() function do in Python? A. Initializes the class for use. B. This function is called when a new object is instantiated. C. Initializes all the data attributes to zero when called. D. None of the above.

B

What does the function re.search do? A. matches a pattern at the beginning of a string B. matches a pattern at any position in a string C. matches all patterns in s string D. none of the above

B

_____ represents an entity in the real world with its identity and behavior. A. A method B. An object C. A class D. An operator

B

Which Of The Following Statements Are Correct? A. A reference variable is an object. B. A reference variable refers to an object. C. An object may contain other objects. D. An object can contain the references to other objects.

B. A reference variable refers to an object. D. An object can contain the references to other objects.

What Will Be The Output Of The Following Code Snippet? class Sales: def __init__(self, id): self.id = id id = 100 val = Sales(123) print (val.id) A. SyntaxError, this program will not run B. 100 C. 123 D. None of the above

C

Regular expressions allow a user to specify a pattern of text to search for. Regular expressions can be used only in Python. A. True B. False

False

True or False A list contains multiple values in the same data type in an ordered sequence.

False

True or False Every Python function must include a return statement.

False

True or False The following test in a Python shell can prove a string is a mutable data type. >>> a = 'this is a string!' >>> print(a) this is a string! >>> a = "this is a changed string!" >>> print(a) this is a changed string!

False

Escape character \n is printed as:

Newline

In Python, a file has two key properties: a filename (usually written as one word) and a path. A. True B. False

True

On Windows, paths are written using backslashes (\) as the separator between folder names. OS X and Linux, however, use the forward slash (/) as their path separator. Fortunately, this problem can be addressed by the os.path.join() function. A. True B. False

True

Plaintext files contain only basic text characters and do not include any control characteristics such as font, size, or color information. A. True B. False

True

True or False Python expressions consist of values (such as 2) and operators (such as +), and they can always evaluate (that is, reduce) down to a single value.

True

True or False Python program can run on various platforms, including Windows, Linux, MacOS, etc.

True

True or False Python supports procedure-oriented programming as well as object-oriented programming.

True

True or False Strings use indexes the same way as lists do.

True

True or False The following is a valid multiple line comments in Python: """This is a test Python program. Written by a student in IT170. This program was designed for Python 3, not Python 2. """

True

True or False While the integer, floating-point, and string data types have an unlimited number of possible values, the Boolean data type has only two values: True and False.

True

We can save a dictionary object in a Python program to a binary shelf file using the shelve module, and restore data to a dictionary variable later from the hard drive. A. True B. False

True

What is the data type of variable a? >>> a = (1)

int

>>> a, b = 'Alice', 'Bob' >>> a, b = b, a >>> print(a) The result is:

'Bob'

>>> for i in [1, 2]: print(i)

1 2

What is the output of the following code? class change: def __init__(self, x, y): self.x = x + y def display(self): print(self.x) x = 10 y = 20 x = change(x,y) x.display() A. 10 B. 20 C. 30 D. Error message

C

What is the output of the following code? class test: def __init__(self): self.variable = 'Old' self.Change(self.variable) def Change(self, var): var = 'New' obj=test() print(obj.variable) A. Error because function change can't be called in the __init__ function B. New C. Old D. Nothing is printed

C

What is the output of the following code? class test: def __init__(self,a): self.a=a def display(self): print(self.a) obj=test() obj.display() A. Runs normally, doesn't display anything B. Displays 0, which is the automatic default value C. Error as one argument is required while creating the object. D. Error as display function requires additional argument

C

What's the data type of mo in the following? import re phoneNumRegex = re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') mo = phoneNumRegex.findall('Cell: 415-555-9999 Work: 212-555-0000') A. string B. tuple C. list D. a Match object

C

Which Of The Following Statements Is Most Accurate For The Declaration X = Circle()? (Circle is a class) A. x contains an int value. B. x contains an object of the Circle type. C. x contains a reference to a Circle object. D. You can assign an int value to x.

C

Which of the following creates a pattern object? (str is a valid regular expression) A. re.create(str) B. re.regex(str) C. re.compile(str) D. re.assemble(str)

C

What is the output of the following? import re sentence = 'we are humans' matched = re.search(r'(.*) (.*?) (.*)', sentence) print(matched.group()) A. ('we', 'are', 'humans') B. (we, are, humans) C. ('we', 'humans') D. we are humans

D


संबंधित स्टडी सेट्स

ACCT 324 - Smartbook Ch. 18 - Contracts in Writing

View Set

Registered Behavior Technician (RTB) certification study guide

View Set

Unit 4 - 403(b) Plans (Tax Exempt Organizations)

View Set

Chapter 10: Health Assessment of Children

View Set

EMT Chapter 24 - Trauma Overview Quiz

View Set

Chapter 3: The Organic Molecules of Life

View Set