Day 08: Developing Programming Habits in 21 Days – Python Problem Solving

Learn programming with Lao Ma by “leveling up and fighting monsters”!

  • Exams involved: Computer Society Programming Ability Level Certification (GESP), Electronics Society Level Examination
  • Activity content: Provide real exam questions of different levels for students to choose for practice
  • Preparation advice: Choose corresponding questions based on your preparation level
  • Additional value: Can be used as preparation training for whitelist competitions

Day 08: CIE Level 1 2023.09_Programming Problem 36

Score Calculator: Input the scores for Chinese, Math, and English sequentially, calculate the total score and average score, and output them in one line.

Requirements:

(1) When the program starts, ask for the Chinese score;

(2) After entering a number, ask for the Math score;

(3) After entering a number, ask for the English score;

(4) After entering the English score, the program automatically outputs the total score and average score in the format: “Your total score is: * points, average score is: * points”. (Both decimal and integer formats are acceptable)

Input example:

92
98
92

Output example:

Your total score is: 282 points, average score is: 94.0 points

Friendly reminder:

Since the exam platform does not currently support the eval() command, students can use other commands; of course, if you do use it, as long as the program is correct, we will still grade it normally.

Reference program:

Note: For reference only, candidates can design their own as long as the results meet the requirements.

chinese = int(input("输入语文成绩"))
math = int(input("输入数学成绩"))
english = int(input("输入英语成绩"))
total = chinese + math + english
avg = total / 3
print("你的总分为:" + str(total) + "分,平均分为:" + str(avg) + "分")

Day 08: GESP Level 2 2024.03_Xiao Yang’s Sun Matrix

[Submission]

https://www.luogu.com.cn/problem/B3955

[Problem Description]

Xiao Yang wants to construct a sun matrix (where the size is odd), specifically, this matrix has rows, each row contains characters, where the leftmost and rightmost columns are <span>|</span>, and the first row, last row, and the middle row (i.e., the row) have the th character as <span>-</span>, while all other characters are lowercase letters <span>x</span>. For example, a sun matrix looks like this:

|---|
|xxx|
|---|
|xxx|
|---|

Please help Xiao Yang print the corresponding “sun matrix” based on the given .

[Input Description]

One line with an integer (ensured to be odd).

[Output Description]

Output the corresponding “sun matrix”.

Please strictly follow the format requirements for output, do not add any extra spaces, punctuation, blank lines, or any symbols. You should output exactly rows, each row should contain exactly characters, which can be <span>-</span>, <span>|</span>, or <span>x</span>.Your output must match the standard answer exactly to score, please check carefully before submission.

[Sample Input 1]

5

[Sample Output 1]

|---|
|xxx|
|---|
|xxx|
|---|

[Sample Input 2]

7

[Sample Output 2]

|-----|
|xxxxx|
|xxxxx|
|-----|
|xxxxx|
|xxxxx|
|-----|

Reference Program:

'''[GESP202403 Level 2] Xiao Yang's Sun Matrix
https://www.luogu.com.cn/problem/B3955
'''
n = int(input())
for i in range(n):
    buf = ""
    for j in range(n):
        if j == 0 or j == n - 1:
            ch = "|"
        elif i == 0 or i == n - 1 or i == n // 2:
            ch = "-"
        else:
            ch = "x"
        buf = buf + ch
    print(buf)

Day 08: GESP Level 3 2023.06_Spring Outing

[Submission]

https://www.luogu.com.cn/problem/B3842

[Problem Description]

The teacher leads the students on a spring outing. It is known that there are students in the class, each student has a unique number from 0 to . When it is time to gather, the teacher checks whether all students have arrived at the gathering place, and asks the students to report their numbers. The students who have arrived will report, but some mischievous students may report multiple times. Can you help the teacher find out which students have not arrived?

[Input Description]

The input contains 2 lines. The first line contains two integers and , indicating that there are students in the class, and the students report their numbers a total of times. It is agreed that .

The second line contains integers, which are the reported numbers from the times.

[Output Description]

Output one line. If all students have arrived, output ; otherwise, output all the numbers of students who have not arrived in ascending order, separated by spaces.

[Sample Input 1]

3 3
0 2 1

[Sample Output 1]

3

[Sample Input 2]

3 5
0 0 0 0 0

[Sample Output 2]

1 2

Reference Program:

'''GESP202306 Level 3 Spring Outing
https://www.luogu.com.cn/problem/B3842
'''
# Input the number of students expected and the number of reports
N , M = map(int,input().split()) 
# Set of reported numbers, deduplicated, M is not used
outSet = set(map(int,input().split()))
allNumSet = set(range(N))
if outSet == allNumSet:
    print(N)
else:
    print(" ".join(map(str,sorted(allNumSet - outSet))))

Day 08: CIE Level 4 2023.03_Problem 36

The transposition cipher method is a method of encryption that rearranges the positions of characters in plaintext according to certain rules to obtain ciphertext. A specific transposition cipher method is as follows: first, group the plaintext into fixed lengths (4 characters per group), and then perform transposition operations on each group of characters to obtain ciphertext. For example, the string “ceit”, when encrypted using the key 1432, first groups the string into 4 characters, then transposes the characters in each group, keeping the 1st and 3rd characters in place, while swapping the 2nd and 4th characters, resulting in the ciphertext “ctie”. The program written by Xiao Zhang is as follows, please complete the code in the underlined parts:

def jiami(yw, key):
    result = ''
    for i in range(0, _____①_____, len(key)):
        s1 = yw[i:i + len(key)]
        for j in range(_____②_____):
            result = result + _____③_____
    return result


yw = input('请输入待加密的明文:')
key = input('请输入密钥:')
mw = _____④_____
print(mw)

The running result is shown in the figure below:

请输入待加密的明文:abcdefghwxyz
请输入密钥:4321
dcbahgfezyxw

Reference Answers:

<span>len(yw)</span>

<span>len(key)</span>

<span>s1[int(key[j]) - 1]</span>

<span>jiami(yw, key)</span>

Youth Programming Competition Exchange

The “Youth Programming Competition Exchange Group” has been established (suitable for youth aged 6 to 18). Add the assistant on WeChat to invite everyone into the learning group. After joining the group, everyone can participate in regularly organized 21-day problem-solving check-ins, level exam assessments, Ministry of Education whitelist competition coaching, and youth programming team competitions.

Day 08: Developing Programming Habits in 21 Days - Python Problem Solving

Leave a Comment