前言

这是2024-BUAA-Python 课程的一些经验分享。
该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python

选择题

  • Which option is the result of 100//3?
    A. 33
    B. 34
    C. 33.333333333333333
    D. 0.333333333333333

  • x is a two-digit integer variable. Which statement swaps its tens and units digits?
    A (x%10)10+x%10
    B (x%10)
    10+x//10
    C (x/10)%10+x%10
    D (x/10)%10+x//10

  • The output of the following code is ();

    a,b,c,d,e,f = 'Python'
    b =

    A.1
    B.0
    C.Error
    D.’y’

  • Which of the following statements is illegal in Python ()?
    A. x = y = z = 1
    B. x = (y = z + 1)
    C. x, y = y, x
    D. x += y

  • Which of the following statements about Python’s floating-point type is wrong ?

    A. There are two ways to represent floating-point numbers: decimal notation and scientific notation

    B. The floating-point type is consistent with the concept of real numbers in mathematics, representing values with decimals

    C. sys.float_info can list in detail the floating-point parameters of the system where the Python interpreter runs

    D. Floating-point numbers in the Python language can be without decimals

填空题

  1. The result of the Python statement ‘’.join(list(‘hello BUAA!’)) is__!

  2. In Python, modules can be imported using the keyword _ .

  3. In Python, statement blocks are divided by _. (indentation/brace/line breaks)

  4. The output of excuting the code blow is __
    tmp = ‘ab’ + ‘c’*2
    print(tmp)

  5. Consider the following code snippet:
    x = [1, 2, 3, 4]
    y = [num * 2 for num in x]
    The value of y after execution is _ .

编程题

  1. 平方和
    【Description】
    The user inputs a positive integer n . Calculate the sum of squares from 1 to n (1^2 + 2^2 + ….+ n^2).
    【Input】
    A line contains an integer n.
    【Output】
    The result of the sum of squares from 1 to n
    【Examples Input】
    3
    【Examples output】
    14
    【Example description】
    1^2 + 2^2 + 3^2 = 14
    【Notes】
    For 100% of test cases, a,b in [1, 10000].
  2. Calculate GPA
    【Problem Description】
    Li Hua is a student of Beihang University. Can you help him calculate his GPA this semester using Python?

    To calculate GPA, you need to use the following method:
    First, ignore all courses with less than 1 credit (not including 1).
    Then, calculate the grade point for each course: Assume x is the original score of the course,
    $GP = \begin{cases}
    4 - 3 \cdot \frac{(100-x)^2}{1600} & \text{if } x \geq 60 \
    \newline
    0 & \text{if } 0 \leq x < 60
    \end{cases}$
    Next, you need to know how many credits were given for each courses.
    After calculating all the steps above, you need to calculate $ GPA = \frac {\sum(GP_i * Gredit_i)}{\sum Gredit_i} $, where credit and GP is given above.
    【Input】
    First line, an integer N, tells how many courses Li Hua has taken this semester.
    Then followed by two lines, each line 2 numbers (integer or float) X C separated by space. The first integer X is the original score of the course, and the second num C is the credit for the course.
    【Output】
    A floating point rounded to 2 decimals, which is the GPA.
    【Sample Input】
    4
    100 1
    60 1
    0 1
    90 0.2
    【Sample Output】
    1.67
    【Sample Description】
    The first course has a GP of 4.0, the second course has a GP of 1.0, and the third course has a GP of 0. The fourth course does not count at all.
    GPA=(4.0+1.0+0)/(1+1+1)=1.67
    【Data】
    1<=N<=1000, N is integer.
    0<=X<=100, X is integer.
    0<=C<=6, C is float or integer.
    All data satisfy that there is at least one class has more than 1 credit.