End-of-term review questions for data analysis using Python

Article directory

1. Multiple choice questions

         2. Fill in the blanks

3. True or False Questions

4. Code analysis questions

5. Procedural questions


1. Multiple choice questions

1. The result of sum(range(0,101) is ( )

A.5050      B.5151       C.0        D.101

A

2. Which of the following is not a valid python identifier ()

A.int32     B.70XL       C.self        D.__name__

B

3. The value of 'abcabcabc'.count('abc') is ()

A.9             B.1             C.3               D.0

C

4. as follows

str1=”Runoob example......WoW!!!”

Str2=”exam”;

The result of Print(str1.find(str2,5)) is ()

A.6        B.7        C.8        D.-1

B

5. The following description about dictionary operations is wrong ()

A.del is used to delete dictionaries or elements

B.clear is used to clear the data in the dictionary

The C.len method can calculate the number of key-value pairs in the dictionary

The D.keys method can get the value view of the dictionary

D

6. In python, the function definition may not include the following ()

A. Function name B. Keyword def C. A pair of parentheses D. Optional parameter list

D

7. In python, the data structure is divided into variable type and immutable type. The following immutable types are ()

A. The keys in the dictionary

b. list

C. collection

D. Dictionary

A

8. The result of Print(2**4+16%3) is ()

A.17        B.21       C.9      D.13

A

9. Which of the following is not the definition of a Python tuple ()

A.(1) B.(1,) C.(1,2)   D(1,2,(3,4))

A

10. Which of the following statements about python assignment is wrong ()

A.Python supports chain assignment and multiple assignment

B. The same variable name in Python can be assigned different types of values ​​in different positions

C.Python assignment is case insensitive

D. There is no need to explicitly declare the type of the variable in Python, and the type is determined according to the "value"

C


2. Fill in the blanks

1. Suppose a, b=10, 50, then the value of the conditional expression a>10andb<100 is_______

False

2. The value of the expression len('SDIBT') is __________

5

3. It is known that x=[1, 2, 3, 2, 3], after executing the statement x.pop(), the value of x is_____

[1,2,3,2]

4. Given mylist=[1,7,3,4,5,6,7,8,11,19,20], what is the result of executing mylist[-1:7:-1]________

[20,19,11]

5. The ____ method of the dictionary object can clear all entries in the dictionary at one time

clear()

6. It is known that x=[1,2,3,4,5], then after executing the statement del x[1:3], the value of x is ______

[1,4,5]

7. The ______ function in pandas is mainly used to apply various JOIN operations to your data

merge()/join

8. The ______ function reads delimited data from a file, URL or file object, comma is the default delimiter.

read_csv()

9. If the parameter method in the fillna function is set to 'ffill', it means that _____ fills the NaN value.

forward

10. The function used to calculate the square root in the Python standard library math is _____

sqrt

11. It is known that x = list(range(20)), then the output of the statement print(x[100:200]) is _____________

[ ]


3. True or False Questions

1. Anything placed between a pair of triple quotes will be considered a comment ()

×

2. Lists, tuples, and strings are ordered sequences in python, dictionaries and sets are unordered sequences ()

3. Lists are mutable objects in python, tuples and strings are immutable objects ()

4. The method randint(m,n) of python standard library random is used to generate a random integer between m and n ()

5. The value in the dictionary does not allow duplicates ()

×

6. Using the to_csv method of DataFrame, the data can be exported as a comma-separated file ()

7. The unstack() operation on the DataFrame will pivot the data in the row to the column()

8. When using the python list method insert() to insert elements into the list, the index of the element after the insertion position in the list will be changed ()

9. Python collections can contain the same elements ()

×

10. It is known that x=(1,2,3,4), then after executing x[0]=5, the value of x is (5, 2, 3, 4) ()

×


4. Code Analysis Short Answer Questions

1. Write the final running result of the program

import pandas as pd
Import numpy as np
f3=pd.DataFrame({‘lkey’:[‘b’,’b’,’a’,’c’,’a’,’a’,’b’],’data1’:range(7)})
f4=pd.DataFrame({‘rkey’:[‘a’,’c’,’d’],’data2’:range(3)})
Print(pd.merge(df3,df4,left_on=’lkey’,right_on=’rkey’))

        Lkey   data1  rkey   data2

0          a        2        a        0

1          a        4        a        0

2          a        5        a        0

3          c        3        c        1

2. Multidimensional array slices (three-dimensional, four-dimensional)

3. Write the final running result of the program

import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
rect = plt.Rectangle((0.2, 0.75), 0.4, 0.15, color='k', alpha=0.3)
circ = plt.Circle((0.7, 0.2), 0.15, color='r', alpha=0.3)
pgon = plt.Polygon([[0.15, 0.15], [0.35, 0.4], [0.2, 0.6]], color='g', alpha=0.5)
ax.add_patch(rect)
ax.add_patch(circ)
ax.add_patch(pgon)

4. Data aggregation and grouping operations

5. Please describe how lists and tuples are defined and the differences between them

The difference between list and tuple

The difference: the way of definition: list[] tuple()

list is mutable tuple() is immutable

There are append() and insert() functions in List, but not in tuple

The same point: they are all ordered collections (containers)

5. Procedural questions

1. Program to calculate the sum of odd and even numbers within 100 (including 100)

s1,s2=0,0
for i in range(1,101):
   If i%2==1:
      s1=s1+i
else:
      s2=s2+i
Print(s1,s2)

2. There are four numbers: 1, 2, 3, 4, how many different three-digit numbers can be formed without repeated numbers

n = 0
for x in range(1, 5):
        for y in range(1, 5):
            for z in range(1, 5):
                if (x != y) and (y != z) and (z != x):
                    print("%d%d%d" % (x, y, z), end=",")
                    n += 1
print()
print(n)

3. Determine how many prime numbers there are between 1000-2000, and output all prime numbers.

n=0
for i in range(1000,2001):
    a=2

    while a<i: #
        if i%a==0:break
        else:a=a+1
    if a==i:
        n+=1
        print(i)
print(n)

4. Print out all the "four-leaf rose numbers". The so-called "four-leaf rose numbers" refer to a four-digit number, and the sum of the fourth powers of each digit is equal to the number itself.

for i in range(1000,10000):
  a = int(i/1000)
  b = int(i%1000/100)
  c = int(i%100/10)
  d = int(i%10)
  if pow(a,4)+pow(b,4)+pow(c,4)+pow(d,4)==i:
    print(i)

5. Input a line of characters, count the number of English letters, spaces, numbers and other characters output, and count the number of each type.

InPut = input('请输入字符串:')
letters = [ ]
spaces = [ ]
digits = [ ]
others = [ ]
for i in iter(InPut):
 if i.isalpha():
  letters.append(i)
 elif i.isspace():
  spaces.append(i)
 elif i.isdigit():
  digits.append(i)
 else:
  others.append(i)
print('''
字母: {}, 个数: {}
空格: {}, 个数: {}
数字: {}, 个数: {}
其他: {}, 个数: {}'''\
.format(letters, len(letters), spaces, len(spaces), digits, len(digits),others, len(others)))

6. Print the ninety-nine multiplication table.

i = 1
while i < 10:
    j = 1
    while j <= i:
        print(str(j)+"*"+str(i)+"="+str(i*j),end="\t")
        j = j + 1
    print("")
    i = i + 1

Guess you like

Origin blog.csdn.net/qq_51601455/article/details/127715954