Beruflich Dokumente
Kultur Dokumente
9 How do you change the file position to an offset value from the start?
a. fp.seek(offset, 0)
b. fp.seek(offset, 1)
c. fp.seek(offset, 2)
d. none of the mentioned
12 How do you get the name of a file from a file object (fp)?
a. fp.name
b. fp.file(name)
c. self.__name__(fp)
d. fp.__name__()
a. Hello
b. Something went wrong
c. Nothing went wrong
d. Hello/ Nothing went wrong
a. x
b. An exception occurred
c. Error
d. None of the Above
23 What will be the output of the following snippet?
try:
print(x)
except:
print("Something went wrong")
finally:
print("The 'try except' is finished")
d. FileNotFoundError
35 Find the error:
>>> a=[1,2,3,4,5]
>>> print(a[7])
a. KeyError
b. ValueError
c. TypeError
d. IndexError
a. KeyError
b. ValueError
c. TypeError
d. IndexError
37 How do you change the file position to an offset value at the start?
a. fp.seek(offset, 0)
b. fp.seek(offset, 1)
c. fp.seek(offset, 2)
d. none of the mentioned
38 How do you change the file position to an offset value at current position ?
a. fp.seek(offset, 0)
b. fp.seek(offset, 1)
c. fp.seek(offset, 2)
d. none of the mentioned
a. KeyError
b. ValueError
c. TypeError
d. EOFError
40 Find the error:
for i in range(1,6):
print(i)
a. KeyError
b. ValueError
c. IndentationError
d. EOFError
41 What is the command for package downloading in python.org?
a. KeyError
b. ValueError
c. ZeroDevisionError
d. EOFError
44 If you try to open a file that doesn’t exist, you get an_________________
a. KeyError
b. ValueError
c. IOError
d. EOFError
45 import sys
a = argv[1].split()
dict = {}
for i in a:
if i in dict: dict[i]=dict[i]+1
else:
dict[i] = 1
print(dict) print(len(a))
Output
C:\Python34>python .exe word.py
"python is awesome lets program in python"
Find the output for word count:
a. {'lets': 1, 'awesome': 1, 'in': 1, 'python': 2, 'program': 1, 'is': 1}
b. {'lets': 1, 'awesome': 1, 'in': 2, 'python': 2, 'program': 1, 'is': 1}
c. {'lets': 2, 'awesome': 1, 'in': 1, 'python': 2, 'program': 1, 'is': 1}
d.Error
46 To open a file c:\scores.txt for read and write, we use ____________
a) outfile = open(“c:\\scores.txt”, “r+”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “w”)
47 To open a file c:\scores.txt for write and read, we use ____________
a) outfile = open(“c:\\scores.txt”, “w+”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “r”)
48 To open a file c:\scores.txt for write, we use ____________
a) outfile = open(“c:\\scores.txt”, “w+”)
b) outfile = open(“c:\\scores.txt”, “rw”)
c) outfile = open(file = “c:\scores.txt”, “w”)
d) outfile = open(file = “c:\\scores.txt”, “r”)
49 If you don’t have permission to access a file. you get _____________
a. KeyError
b. ValueError
c. PermissionError
d. EOFError
50 A package is a folder containing one or more Python modules. One of the modules in a
package must be called__________________
a. main.py
b. _init_.py
c. package.py
d. init.py