前言

该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python

选择题

  1. Which of the following options is not a reserved word in the Python programming language?
    A. pass
    B. while
    C. do
    D. except

  2. Which of the following options does not comply with the variable naming rules in the Python programming language?
    A. 33keyword
    B. keyword_33
    C. 33_keyword
    D. keyword33

  3. Regarding the eval function, which of the following options describes incorrectly:
    A. The execution of eval(“Hello”) and eval(“ ‘Hello’ “) yields the same result.
    B. The definition of the eval function is: eval(source, globals=None, locals=None, /)
    C. If a user wants to input a number and perform calculations on it using a program, they can use the combination eval(input(<输入提示字符串>))
    D. The purpose of the eval function is to convert the input string into a Python statement and execute that statement.

  4. Given a dictionary d, which of the following options correctly describes d.get(x, y)?
    A. Returns the value in dictionary d with key x, if it exists; otherwise, returns y.
    B. Returns the value in dictionary d with value y, if it exists; otherwise, returns x.
    C. Returns the value in dictionary d with key x, if it exists; otherwise, returns x.
    D. Returns the value in dictionary d with key-value pair x:y.

  5. The output result of the code below is:

    a = 4
    a ^= 3
    b = a ^ 2
    print(a,end=",")
    print(b)```
    A. 64, 4096
    B. 4,3
    C. 5,7
    D. 7,5

填空题

  1. Given x = {‘a’: ‘b’, ‘c’: ‘d’}, the value of the expression ‘a’ in x is .

  2. Given x = {‘a’: ‘b’, ‘c’: ‘d’}, the value of the expression ‘b’ in x.values() is True .

  3. The value of the expression (1,3)+(5,7) is (1, 3, 5, 7) .(With () and commas)

  4. For the list L=[2, 16, 36, 64], after executing L.insert(0,10), the value of L is [10, 2, 16, 36, 64] . (With [] and commas)

  5. When executing the statement print(set([1,2,2,3])[3]), the reason for error in execution is set is not subscriptable . (index error/set is not subscriptable)

编程题

第一题

【Description】

Give a series of dish names, output the menu after removing the duplicate dishes and sorting them in ascending order.

【Input】

A line of dish names separated by spaces indicates the recipe obtained.

【Output】

A line of dish names separated by spaces indicates the recipe after removing the duplicate.

【Example Input】

pizza donut hamburger chips hamburger donut juice
【Example Output】

chips donut hamburger juice pizza
【Notes】

Set () can convert a list into a collection,Consider using the set data type feature to remove duplicate elements

You can use. Join() to get a string that represents a list joined by spaces.

The list containing strings can also be sorted using the sort() method

第二题

【Description】

Input the string containing the ‘-‘ extension from the keyboard, expand it into equivalent complete characters, for example, expand A-D to ABCD, and output the extended string.

Requirements: (1) The string to be extended contains at most one extender and no spaces(2) The characters before and after the extender must be in the range of [a-z], [A-Z] or [0-9] before extender expansion, and the extended characters must also be in this range. The ASCII code before the hyphen is smaller than that after the hyphen can be expand. In other cases, they will not be expanded and will be output as is. For example, 5-d will be extended to

56789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd.
【Input】

Enter a string containing an extension from the keyboard

【Output】

Output extended string

【Example Input1】

ADEa-g02
【Example Output1】

ADEabcdefg02
【Example Input2】

T-bcd
【Example Output2】

TUVWXYZabcd
【Example Description】

The input ADEa-g02 of example 1 is extended to adeabcdefg02,In the input T-bcd of example 2, because the ASCII value of B is larger than t, it also needs to be expanded, but only the English letters between T and b are expanded. The expansion result is tuvwxyzabcd.

【Notes】

The length of input and output strings should not exceed 100.