Python-Quiz 7 (mooc)

1
1
point # 0033003400340034003600321587046818563 two-dimensional list ls = [[1,2,3], [4,5,6], [7,8,9]], which option can get the element 5? ls
[-1 ] [-1]
ls [4]
ls [-2] [-1]
ls [1] [1] The
correct answer D
This is how to use two-dimensional slices.

2
1
min # 0033003400340034003600321587046818565 With regard to the close () method of file closing, which option is described correctly? file
follow strict "Open-Operation-Close" mode
after file processing, you can close the file without the close () method. When the program exits, the
file will be closed by default. After the file processing is completed, you must close the file with the close () method.
If the file is opened in read-only mode, only In this case, you can close the file without using the close () method.
Correct answer B. It
is a good habit to close the file with close () after opening the file. If close () is not called, the file reference is released when the current Python program is completely run and exited, that is, when the program exits, it is equivalent to calling close ().

3
1
point # 0033003400340034003600321587046818566 Regarding the dimensions of data organization, which option is described incorrectly?
the use of two-dimensional
High-dimensional data is composed of key-value pairs of data, and is organized in the form of objects.
One-dimensional data is organized in a linear manner. Corresponding to the conceptual
data in mathematics, such as arrays and collections, there are dimensions and dictionaries. The type is used to represent one-dimensional and two-dimensional data. The
correct answer D
dictionary is used to represent high-dimensional data, generally not used to represent one-dimensional data.

4
1
minute # 0033003400340034003600321587046818567 The following options describe the file incorrectly: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‬‪‬‪‪‪‬‬‬ ‬‬ ‬ file
is a collection of abstract data
file is a collection of abstract and program
files are stored on the data sequence in the auxiliary memory
file may contain anything
correct answer B
function or class is a collection of program and abstract, not a document .

5
1
minute # 0033003400340034003600321587046818568 Given a list ls = [1, 2, 3, "1", "2", "3"], its elements contain 2 data types, which option is the data organization dimension of the list ls?
cube
-D Data
High-dimensional data
One-dimensional data
Correct answer D
If the list elements are all lists, it may represent two-dimensional data, for example: [[1,2], [3,4], [5,6]].

If the list elements are not all lists, then it represents one-dimensional data.

6
1
point # 0033003400340034003600321587046818569 The following options are not Python file reading operations: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪ ‪‪‬‪ ‪ ‬ ‬ ‬ readline
()
readtext ()
readlines ()
the Read ()
the correct answer B
is not readtext () method

7
1
point # unified step 0033003400340034003600321587046818570Python for file operations is used: open
- operation - Close
open - read - write
operations - read - write
open - read - write - Close
the correct answer a
opening - operation - is a uniform closing step, wherein the closing Can be omitted.

8
1
point # 0033003400340034003600321587046818573 For Python files, the following description is correct: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‪‪‪‪ ‬ ‬ when the
file is opened in binary mode, according to the read character string
when the text file is opened in read mode a byte stream in accordance with the
open file can either use the same text, may be employed opened in binary mode
depending on the type of file, open a text or binary only the
correct answer C
file There, binary or text only way to open the understanding of its different programs.

9
1
point # 0033003400340034003600321587046818574 Regarding the description of the CSV file, which option's description is wrong? CSV
files and more A variety of encodings represent characters. The
entire CSV file is a two-dimensional data
. Each line of the CSV file is one-dimensional data. You can use the list type in Python to indicate that the
CSV file format is a universal and relatively simple file format. It is used between programs. Transfer table data
Correct answer A
Generally speaking, CSV files are all text files, composed of the same encoded characters.

10
1
min. # 0033003400340034003600321587046818574 Regarding the '+' open mode of Python files, which option is correct? cover
write mode
and Use r / w / a / x together to add simultaneous read and write functions on the basis of the original function.
Read-only mode.
Additional write mode.
Correct answer B.
The essence of the '+' open mode is that it can give read and write permissions to files at the same time.

003600321587046835604
average number of text columns
described
Mean column printout file attachment, calculated as follows: ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬

(1) Valid line refers to a line containing at least one character, blank lines are not counted; ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‪‪ ‪‬‪‬‪‬‪‬‮‬‪‬‭‬

(2) The number of columns in each line is the number of effective characters; ‪‬‪‬‮‬‪‬‭‬

(3) The average number of columns is the average value of the number of columns in the effective row, and the integer rounding is adopted by rounding.

lineSum=0
n=0
with open("latex.log",'r',encoding='utf-8') as f:
    for line in f:
        if len(line)-1==0:
            continue
        lineSum+=len(line)-1
        n+=1
print(int(lineSum/n))

0034003600321587046853184
CSV format conversion cleaning and
described
accessory is a CSV format file, extract data format conversion as follows: ‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬

(1) row by reverse order; ‬‪‬‭‬

(2) each row of data in reverse order; ‬‪‬‭‬

(3) Use a semicolon (;) instead of a comma (,) to separate data without spaces; ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬

The data will be output after conversion according to the above requirements.

ls=[]
with open("data.csv",'r',encoding='utf-8') as f:
    for line in f:
        line=line.replace("\n",'')
        line=line.replace(" ",'')
        ls.append(line.split(',')[::-1])
    ls=ls[::-1]
    for i in ls:
        print(';'.join(i)) 
Published 29 original articles · praised 0 · visits 475

Guess you like

Origin blog.csdn.net/qq_43771959/article/details/105568636