前言

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

选择题

  • Which of the below Python data type is mutable? _
    A. Tuple
    B. String
    C. List
    D. Dictionary

  • Which Python built-in function is used to remove and return an element from a list? _
    A. append()
    B. remove()
    C. pop()
    D. sort()

  • The following is a piece of code that sums up all the values in a dictionary and prints the result:

    d = {"a": 1,  "b": 2,  "c": 3}
    total = ___
    print(total)

    Please fill in the blanks in the code. _
    A. sum(d)
    B. sum(d.values())
    C. sum(d.keys())
    D. sum(d.items())

  • In Python, which of the following option(s) can be used to sort the keys in a dictionary? _
    A. dict.keys()
    B. dict.sort()
    C. sorted(dict)
    D. sort(dict.keys())

  • Which of the following option(s) can be used to merge the keys and values of a dictionary into a new string?Assuming that both the keys and values of the dictionary are strings. _
    A. list(dict.merge())
    B. “”.join(list(dict))
    C. “”.join(list(dict.items()))
    D. “”.join(list(dict.keys()) + list(dict.values()))

编程题

1

【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 least one extender and does not contain spaces( 2) It only deals with the character extension in the range of [a-z], [A-Z] and [0-9], that is, only when the characters before and after the extension are lowercase letters, uppercase letters or numbers at the same time, it can be extended. In other cases, it will not be extended and output as is. For example, strings such as a-R, D-e, 0-B, 4-b are not extended.
【Input】
Enter a string containing an extension from the keyboard
【Output】
Output extended string
【Example Input】
ADEa-g02
【Example Output】
ADEabcdefg02
【Notes】
The length of input and output strings should not exceed 100

2

【Problem Description】

At the end of a semester, the head teacher Li Hua obtained the grades of each subject for the whole class. He wanted to calculate the average score of each subject (Chinese, Mathematics, English) for the whole class. However, he accidentally mixed up the scores. Please write a program in Python to help him fix the issue.

【Input form】

The first line, an integer n, represents the number of people in the class.

For the next 3n lines, each line represents a student’s grades for a course. The format each line consists of two parameters, a and b, separated by a space in between. Parameter a is a floating-point number representing the scorer of the exam. Parameter b is a string (Chinese, Math, English) representing the subject.

It is guaranteed that each student has one and only one score for each subject. Hence in the above data, Chinese, Math, and English will only appear n times each for n number of students.

【Output format】

Three lines, each line with a floating-point number (two digits), are the average scores for Chinese, Mathematics, and English.

【Sample input】
3
100.0 Chinese
100.0 Math
90.5 English
90.5 Math
89.5 Chinese
99.5 Chinese
60.0 English
80.0 Math
72.5 English

【Example output】

96.33
90.17
74.33

【Example description】

For the above inputs, the average score for Chinese is 96.33, the average score for mathematics is 90.17, and the average score for English is 74.33

【Data range】
1<=n<=30000, 0<=a<=100, b∈{‘Chinese’, ‘Math’, ‘English’}