IT 109 GMU Final review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/58

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

59 Terms

1
New cards

Which of the following is not a valid variable name?

A. BOO

B. foo

C. 2BOO

D. too

C. 2BOO

2
New cards

Which of the following is the extension for python file?

A. .pyc

B. .py

C. .doc

D. None of the above

B. .py

3
New cards

Which one of the following constitutes a proper email subject header for an email sent from student Mickey Student to the professor?A. IT109_section0xx_Mickey_Student

B. IT109

C. "Hi"

D. Should leave blank

A. IT109_section0xx_Mickey_Student

4
New cards

Which of the following is the correct syntax to assign a value 'Harry' to a variable first_name?A. 'Harry' = first_name

B. first_name = 'Harry'

C. first_name == 'Harry'

D. 'Harry' == first_name

B. first_name = 'Harry'

5
New cards

Which of the following is the correct syntax to insert a new line in python outcome?

A. \n

B. \t

C. \r

D. None of the above

A. \n

6
New cards

What is the correct syntax to output 'Hello John' in python?

A. print('Hello John')

B. input('Hello John')

C. print(Hello John)

D. None of the above

A. print('Hello John')

7
New cards

Which of the following is a true statement?

A. Python is case sensitive

B. Python is named after a BBC TV show 'Monty Python's Flying Circus'

C. Python is a open source language

D. All of the above

D. All of the above

8
New cards

Which of the following is an invalid name?

A. MYVARB. my-var

C. my_var

D. myvar

B. my-var

9
New cards

What the following print function will print? (Note escape character \t)print ("Progr\tamming is really fun")

A. Progr amming is really fun

B. Programming is "really" fun

C. "Programming is really fun"

D. Programming is re ally fun

A. Progr amming is really fun

10
New cards

What will be the outcome of the following type conversion if you type it in python shell?>>> int('IT109')

A. Convert to equivalent ASCII code

B. 'IT109'

C. 109

D. Raise an error

D. Raise an error

11
New cards

Which of the following would be considered as a string data type in Python?

A. Foo

B. '4.90'

C. 2.33

D. 5

B. '4.90'

12
New cards

What would be the value of the following expression: (11-4*2)%2

A. 1.5

B. 1

C. 2.0

D. 0

B. 1

13
New cards

What would be the value of the following expression: 2**3 % 4

A. 1

B. 0

C. 5

D. 2

B. 0

14
New cards

What would be the outcome of the following code?

a= 10

b= 20

a+= 2

result = a + b

print (result)

A. 30

B. 31

C. 32

D. 33

C. 32

15
New cards

What does the following code print?total_apple = 2

total_orange= 1

print(total_apple >=total_orange)

A. True

B. False

C. None

D. 0

A. True

16
New cards

What does the following code print?

if 5 > 10:

print('fan')

elif 9!=9=:

print('glass')

else:

print('cream')

A. fan

B. glass

C. cream

D. None of the above

C. cream

17
New cards

The if/elif/else

statement is used for

repetition?

True?

False?

False

18
New cards

The outcome of the following code is 1.

i = 1

if i > 0:

print(i)

True?

False?

True

19
New cards

Which of the following is not an assignment operator?

A. >=

B. =

C. =+

D. **=

A. >=

20
New cards

What is the content of gadgets at the end of the following code?

>>> gadgets =['phone', 'camera', 'laptop', 'tablet']

>>> gadgets.insert(2, 'camera lens')

A. No change to the list

B. ['camera lens', 'phone', 'camera', 'laptop', 'tablet']

C. ['phone', 'camera', 'camera lens', 'laptop', 'tablet']

D. ['phone', 'camera lens', 'camera', 'laptop', 'tablet']

C. ['phone', 'camera', 'camera lens', 'laptop', 'tablet']

21
New cards

What will be the outcome of the following code?

>>> months = ['January', 'March', 'December']

>>> months.append('May")

A. ['May', 'January', 'March', 'December']

B. ['January', 'March', 'December']

C. ['January', 'March', 'December', 'May']

D. ['January', 'March', 'May', 'December']

C. ['January', 'March', 'December', 'May']

22
New cards

How to obtain the list [100, 200, 300] from the following list named numbers?

numbers= [10, 20, 30, 40, 50, 100, 200, 300]

A. numbers[4:]

B. numbers[5:7]

C. numbers[5:]

D. numbers[:]

C. numbers[5:]

23
New cards

How to obtain the word 'greet' from msg= 'greetings'?

A. msg[0:4]

B. msg[0:5]

C. msg[:4]

D. msg[1:5]

B. msg[0:5]

24
New cards

'in' is a keyword that checks for a membership. For example:

>>> 'a' in 'apple'returns True since letter 'a' is in the word 'apple'

>>> 'b' in 'apple'returns False since letter 'b' not in the word 'apply'How many time the following print statement will execute?

word= 'apple'

while True:

if 'p' in 'apple':

print('foo')

break

A. 0

B. 1

C. 2

D. 3

B. 1

25
New cards

What will be the outcome of the following code?

n= 10

while n!= 0:

print(n)n-= 2 #decrease n by 2

A. 10, 9, 8, 7...0

B. 10, 8, 6, 4, 2

C. 1, 2, 3, 4,... 10

D. No outcome

B. 10, 8, 6, 4, 2

26
New cards

How the content of t changes after the following assignment?

>>> t = (1, 2, 3, 10)

>>> t[-1]= 100

A. t= (1, 2, 3, 100)

B. t= (100, 1, 2, 3,)

C. t = (1, 2, 3)

D. Error

D. Error

27
New cards

Which of the following is a true statement about while loop?

A. While loop is controlled by loop variable

B. while loop needs a condition

C. loop Variable needs an initialization

D. All of the above

D. All of the above

28
New cards

What is the outcome of the following code?

n= 0

while n < 5:

print(n)n = n + 1

A. 1,2,3,4,5

B. 5,4,3,2,1

C. 0,1,2,3,4

D. 0

C. 0,1,2,3,4

29
New cards

What will be the outcome of the following operation?

>>> numbers = '22 33 44'

>>> numbers.split()

A. ['22', '33', '44']

B. [22, 33, 44]

C. ['223344']

D. [22, 33]

A. ['22', '33', '44']

30
New cards

What's printed?

def func (a, b, d=7):

return a + b + c + d

a, b, c, d = 2, 4, 6, 8

print(func(a, 5, d = 2))

A .12

B. 15

C. 20

D. None of the above

B. 15

31
New cards

What's printed?

def grade (score):

if score > 60:

return "D"

elif score > 70:

return "C"

elif score > 80:

return "B"

elif score > 90:

return "A"

else:

return "F"

print(grade(92))

A

B

C

D

D

32
New cards

What is the value of "count" at the end of the for loop?

number=5

count=1

for i in range (number):

count= i**2

print(count)

A. 5

B. 0

C. 16

D. 1

C. 16

33
New cards

How many times the following print statement will execute?

for x in range (10, 5, -2):

print(x)

A. 1

B. 2

C. 3

D. 4

C. 3

34
New cards

How many times the word "PYTHON" will be printed?

word= "PYTHON"

for n in range(3):

print(word)

A. 0

B. 1

C. 2

D. 3

D. 3

35
New cards

Which is true about the order in which function parameters are listed in its definition and when called?

A. Positional parameters must be listed before any keyword (default) parameters

B. keyword (default) parameters must be listed before any positional parameters

C. Either category of parameter may be listed first

D. keyword (default) and positional parameters can be interspersed

A. Positional parameters must be listed before any keyword (default) parameters

36
New cards

When creating your own functions which of the following are good characteristics that make them robust, sharable, and reusable(select all that apply)

A. the function's name is suggestive of its purpose and/or actions and includes a summary docstring

B. the function freely uses variables in the global namespace to perform its activities

C. the function only uses variables it is passed by calling code or it otherwise internally creates

D. the function only performs a limited number of actions

A. the function's name is suggestive of its purpose and/or actions and includes a summary docstring

C. the function only uses variables it is passed by calling code or it otherwise internally creates

D. the function only performs a limited number of actions

37
New cards

What's printed?

def receipt (items):

for n in range (len(items)):

print(n + 1, items [n])

ilist= ["milk", "eggs", "bread"]

receipt (ilist)

A. 0 milk

1 eggs

2 bread

B. 1 milk

2 eggs

3 bread

C. milk

eggs

bread

D. none of the above

B. 1 milk

2 eggs

3 bread

38
New cards

All of the following are namespace in Python except:

A. enclosed

B. local

C. system

D. global

C. system

39
New cards

Variables (identifiers) listed in the parenthesis during function definition are called

A. arguments

B. parameters

C. loop variable

D. return value

B. parameters

40
New cards

What is the outcome of the following code?

>>> person= {"name": "John", "age': 28}

>>> person.pop("address")

A. None

B. KeyError

C. []

D. 0

B. KeyError

41
New cards

How to add a key-value pair ("VA", "Virginia") to a dictionary d?

A. d.append("VA","Virginia")

B. d["VA"]= "Virginia"

C. d.add("VA", "Virginia")

D. d.put("VA", "Virginia")

B. d["VA"]= "Virginia"

42
New cards

Suppose d= {"VA":1, "WV":2}, if we try to retrieve a value using the expression s["CA"]?

A. Since "CA" is not a value in the set, Python raises a KeyError exception

B. It is executed fine and no exceptions is raised, and it returns None

C. Since "CA" is not a key in the set, Python raises a KeyError exception

D. Since "CA" is not a key in the set, Python raises a syntax error

C. Since "CA" is not a key in the set, Python raises a KeyError exception

43
New cards

What is the correct syntax to remove "Emma" from a dictionary person?

person= {"name": "Emma", "age": 34, "address": "4400 University Dr."}

A. del person["name"]

B. delete person.name("Emma")

C. remove(person["name"])

D. person.del("name", "Emma")

A. del person["name"]

44
New cards

What will be the outcome of the following code?

my_dict= {1:1, 2:2, 3:4}

sum= 0

for k in my_dict:

sum +=my_dict[k]

print(sum)

A. 6

B. 7

C. 8

D. 9

B. 7

45
New cards

Which of the is true?

A. Dictionary is composed of keys only

B. Dictionary works as a look up table

C. Dictionary is a sequential data structure

D. None of the above

B. Dictionary works as a look up table

46
New cards

What is the correct way to get person's age from the following dictionary?

person= {"name": "Jane Doe", "age": 45, "address": "4400 University Drive, Fairfax, VA"}

A. persons{"age"}

B. person("age")

C. person ["age"]

D. all of the above

C. person ["age"]

47
New cards

Suppose d= {"Ben":"A+", "Jane":"B+"} and if you do d.items() then what will it return?

A. None

B. only values

C. only keys

D. all the key value pairs

D. all the key value pairs

48
New cards

What is the correct way to update a the key-value pair (1, "one") in the following number dictionary?

number = {1: "one", 3:"THREE", 90: "NINETY"}

A. number["one"]= "ONE"

B. number["ONE"]= 1

C. number[0]= "ONE

D. number[1]= "ONE"

D. number[1]= "ONE"

49
New cards

What would be right syntax to delete an item from a dictionary d?

A. del d[key]

B. delete d[key]

C. d.remove(key)

D. dictionary items cannot be deleted

A. del d[key]

50
New cards

The basic steps in file processing are:

A. read, process, open, close

B. open, close, process, close

C. open, read, process, close

D. process, open, close, read

E. None of the above

C. open, read, process, close

51
New cards

For the given code, the program reads the entire content assuming file path exists and its path is correct as specified.

fp= open("input.txt", "r")

fp.readline()

fp.close()

True

False

False

52
New cards

(True/False) Following code executes in the order of blocks: try, else, finally.

try:

"1" + 1

except:

print("Invalid")

else:

print("Valid")

finally:

print("Bye")

True

False

False

53
New cards

When writing to a file using this statement:

fp.writelines(outdata)

What is true about "outdata"?

A. It's the name of the file being written to

B. It's a variable holding the name of the file being written to

C. It's a string wariable holding the characters the be written to the file pointed to by "fp"

D. It's a list variable consisting of one or more strings to be wrtitten to the file pointed to by "fp"

D. It's a list variable consisting of one or more strings to be wrtitten to the file pointed to by "fp"

54
New cards

Given the following lines of a text file called "states.txt":

Alabama

Alaska

Arizona

What is the content of plines of the following code?

fi= open("states.txt")

plines= fi.readlines()

fi.close()

A. ["Alabama\n", "Alaska\n", "Arizona\n"]

B. Alabama

Alaska

Arizona

C. "Alabama\nAlaska\nArizona\n"

D. none of the above

A. ["Alabama\n", "Alaska\n", "Arizona\n"]

55
New cards

Correct way to open a file in write mode is:

f= open("input.txt")

True

False

False

56
New cards

Outcome of the following code?

try:

print(10/2.0)

except ZeroDivisionError:

print("Invalid")

5

57
New cards

finally block will execute only if there is an exception in the try-except-else-finally syntax

True

False

False

finally block will always execute

58
New cards

(True/False) The following code generates a SyntaxError.

>>> num= float("Hello")

True

False

False

Value Error

59
New cards

What would be written to "q5.in" file assume the file already exists and it's a blank file?

Choose the most appropriate answer.

f= open("q5.in", "r")

f.write("test file\n")

f.close()

A. "test files"

B. "test file" string followed by new line

C. Nothing will be written to the file

D. raise and error

D. raise and error