CS1101 Unit 8 Quiz PDF

Title CS1101 Unit 8 Quiz
Course Programming Fundamentals
Institution University of the People
Pages 8
File Size 147.8 KB
File Type PDF
Total Downloads 50
Total Views 135

Summary

Download CS1101 Unit 8 Quiz PDF


Description

Self-quiz 8 review Question 1 What is the output of the following Python program? try: fin = open('answer.txt') fin.write('Yes') except: print('No') print('Maybe') Select one: a. b. c. d.

Yes No Maybe Yes Maybe e. No Maybe The correct answer is: No Maybe

Question 2 What is the output from the following interactive Python statement? >>> '%g' % (0.1) Select one: a. b. c. d. e.

'0' '0.1' TypeError: float argument required, not str TypeError: not all arguments converted during string formatting TypeError: not enough arguments for format string

The correct answer is: ‘0.1’

Question 3 Handling an exception with a try statement is called throwing an exception. Select one:

True False The correct answer is: ‘False’

Question 4 What is the output of the Python code below? print('%d + %d + %d = %d' % (1, 2, 3, 1+2+3)) Select one: a. b. c. d. e.

6 (1 + 2 + 3 = 6) None 1+2+3=6 “1 + 2 + 3 = 6”

The correct answer is: 1 + 2 + 3 = 6

Question 5 Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is fin? Select one: a. b. c. d. e.

A file object A list of characters A list of words A string that may have a newline A string with no newline

The correct answer is: A file object

Question 6 Which of the following Python statements runs without error? Select one: a. open('three.txt').write(3) b. open('three.txt','w').write(3) c. open('three.txt','w').write(str(3))

d. All of the above e. None of the above The correct answer is: open('three.txt','w').write(str(3))

Question 7 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.join(cwd, 'Documents/file.txt') Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: /Users/me/Documents/file.txt

Question 8 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.exists(cwd) Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: True

Question 9 What is the output from the following interactive Python statement? >>> '%g %d' % (0.1) Select one:

a. b. c. d. e.

'0' '0.1' TypeError: float argument required, not str TypeError: not all arguments converted during string formatting TypeError: not enough arguments for format string

The correct answer is: TypeError: not enough arguments for format string

Question 10 What is the output from the following interactive Python statement? >>> '%g' % (0,1) Select one: a. b. c. d. e.

'0' '0.1' TypeError: float argument required, not str TypeError: not all arguments converted during string formatting TypeError: not enough arguments for format string

The correct answer is: TypeError: not all arguments converted during string formatting

Question 11 What is the output from the following interactive Python statement? >>> '%d' % (0.1) Select one: a. b. c. d. e.

'0' '0.1' TypeError: float argument required, not str TypeError: not all arguments converted during string formatting TypeError: not enough arguments for format string

The correct answer is: ‘0’

Question 12 What is the output from the following interactive Python statement? >>> '%g' % '0.1' Select one: a. b. c. d. e.

'0' '0.1' TypeError: float argument required, not str TypeError: not all arguments converted during string formatting TypeError: not enough arguments for format string

The correct answer is: TypeError: float argument required, not str

Question 13 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.isdir(cwd) Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: True

Question 14 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.abspath(cwd) Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: /Users/me

Question 15 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.listdir(cwd)

Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads']

Question 16 Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What does the program loop over? Select one: a. b. c. d. e.

Lines in a file Lines in a list Words in a dictionary Words in a list Words in a string

The correct answer is: Lines in a file

Question 17 Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is word? Select one: a. b. c. d. e.

A file object A list of characters A list of words A string that may have a newline A string with no newline

The correct answer is: A string with no newline

Question 18 Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.isfile(cwd) Select one: a. b. c. d. e.

['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] False True /Users/me /Users/me/Documents/file.txt

The correct answer is: False

Question 19 Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What is line? Select one: a. b. c. d. e.

A file object A list of characters A list of words A string that may have a newline A string with no newline

The correct answer is: A string that may have a newline

Question 20 Exceptions allow the programmer to _________________. Select one: f.

override all runtime errors

g. write code to handle runtime errors h. ignore syntax errors i. load data from a file The correct answer is: write code to handle runtime errors...


Similar Free PDFs