The second provincial match of the 11th Blue Bridge Cup python group-results statistics

1. Problem description:

Xiaolan organized an exam for the students. The total score is 100 points, and each student's score is the same. An integer from 0 to 100. If the score is at least 60 points, it is called a pass. If the score is at least 85 points, it is called excellent. Please calculate the passing rate and the excellent rate, expressed as a percentage, and the part before the percentage sign is rounded to the nearest whole number.
[Input format]
The first line of input contains an integer n, which represents the number of people in the exam.
In the next n rows, each row contains an integer from 0 to 100, representing a student's score.
[Output format]
Output two lines, each line with a percentage, respectively representing the passing rate and the excellent rate. The part before the percent sign is
rounded to the nearest whole number.
[Sample input]
7
80
92
56
74
88
100
0
[Sample output]
71%
43%
[Evaluation use case scale and conventions]
For 50% of evaluation use cases, 1 ≤ n ≤ 100.
For all evaluation use cases, 1 ≤ n ≤ 10000.

2. Thinking analysis:

Analyzing the question, we can know that we traverse the input scores, judge the scores and count the passing and excellent scores respectively. After the loop is over, the passing rate and the excellent rate are obtained. After multiplying by 100, use the round function to round up, and use the round function to round If you don’t write the second parameter, then the decimal is not retained by default, so as to meet the requirement of retaining only integers in the question, and finally convert the rounded result into a string type, and concatenate the character "%".

3. The code is as follows:

if __name__ == '__main__':
    n = int(input())
    jg, yx = 0, 0
    for i in range(n):
        score = int(input())
        if score >= 60:
            jg += 1
            if score >= 85:
                yx += 1
    # 使用round函数对小数进行四舍五入, 不写第二个参数可以不保留小数的位数
    print(str(round(jg / n * 100)) + "%")
    print(str(round(yx / n * 100)) + "%")

 

Guess you like

Origin blog.csdn.net/qq_39445165/article/details/114969597