2023 Lin Ke University Foreign Frequency Blue Python Competition

Participate in the frequency blue python competition on May 17, 2023, leave some questions for the latecomers

1. If you want to output “Life is short, I use Python”, should you use ( )?

  • printf()
  • print()
  • println( );
  • Print( )

2. The output of print(100 – 25 * 3 % 4) is ( ).

  • 1
  • 97
  • 25
  • 0

3. In Python, which of the following variable names is illegal?

  • x123
  • _name
  • post@abc
  • post_abc

4.Str1 = “Python is beautiful!”, the result of the expression str1.isnumeric() is.

  • True
  • 1
  • 0
  • False

5. Among the following options, the identifier that is not legal for Python is ( ).

  • int32
  • 40XL
  • self
  • name

6. The result of executing ‘1234’.find(‘5’) by the Python interpreter is ( ).

  • -1
  • None
  • empty
  • Error reporting

7. The output function of Python is ________.

  • input()
  • print()
  • math( )
  • turtle( )

8. ( ) is an important way to reflect the logical relationship of Python code, and the same code block must ensure the same ( ).

  • indent, indent amount
  • Letter size write, format
  • format, Format
  • constant, variable

9. In Python, the operators listed below cannot be used for tuple operations ( ).

  • +
  • *
  • in

10. When using special characters in a string, python uses ( ) as an escape character.

  • \
  • /
  • #
  • %

11. String s = ‘Python’, output ‘Python111’ after connecting the string s,
Which of the following operations would be wrong?

  • print(s + ‘1 ‘ + ‘1’ + ‘1’)
  • print(s + 111)
  • print( s + str(111))
  • print( s + ‘1’*3)

12. In the method definition of the class, the instance variable x can be accessed through the expression __.

  • x
  • self.x
  • self( x)
  • this. x

13. In Python, for the defined tuple tuple = (‘1’, ‘2’, ‘3’, ‘1’, ‘2’, ‘3’), the following operations cannot be successfully performed ( ).

  • tuple.index(‘2 ‘)
  • tuple. count(‘2’)
  • tuple. pop()
  • len( tuple)

14. It is known that x = {1:2, 2:3, 3:4}, then the value of the expression sum(x) is ( ).

  • 6
  • 9
  • 45
  • 3

15. The result of executing ‘{0},{2},{1}’.format(‘a’,’b’,’c’) by the Python interpreter is ( ).

  • ‘a,b,c ‘
  • ‘a ,c,c’
  • ‘a,c,b’
  • ‘c ,c,b’

16. Which of the following expressions x y to the power of y is correct?

  • x^y
  • x**y
  • x^ ^y
  • x* the y

17. The result of executing print(‘amount: {0:f} yuan’.format(1.5000)) by the Python interpreter is ( ).

  • Amount: 1.5 yuan
  • Amount: 1.500 yuan
  • Amount: 1.500000 yuan
  • Amount: ¥1.50000

18. It is known that x = [3, 5, 7], then after executing the statement x[1:] = [2], the value of x is ( ).

  • [3, 5, 7 ]
  • [3, 2]
  • [3 , 5, 2]
  • [3 ]

19. The construction method is a special method of the class, and its name in Python is ().

  • same name as class
  • __construct
  • _init
  • init

20. For string operations, the execution result of the following statement is:

var1 = 'Hello World!'
print(var1[:6] + 'SDUT!')
  • Hello SDUT!
  • HelloSDUT!
  • Hello WSDUT !
  • WSDUT!

21. The value of the following expression is True ( ).

  • 5 + 4j > 2- 3j
  • 3> 2>2
  • 1==1 and 2!=1
  • not( 1==1 and 0!=1)

22. The execution result of the following code is ( ).

class St:
def __init__(obj,name,age):
obj.name=name
obj.age=age

s=[St("John",19),St("Iris",18),St("Mary",17),St("Jack",16)]
t=0
for i in s:
t + =i.age
t/=4
print(t)
  • 17
  • 16
  • 17.5
  • 18

23. There are two people in the number guessing game, and there are only 7 chances to guess. If one of them guesses a larger number than the other person’s preset number, they will get feedback “guessing too big”. If the guessed number is larger than the preset number If the number is small, you will get feedback “guess is small”, if you guess correctly, you will get feedback “you win”, if you fail to guess 7 times, you will get feedback “you lost”. Read the code below carefully. The numbers Xiao Ming guessed are: 35 10 14 16 28 25 23. How many times did Xiao Ming guess the big number and the small number? Did he get it right in the end?

count=1
a=2
b=4
while True:
^^^^number=a**2 + b**2 + a*b/2 + a*b%2
^^^^ guess=int(input())
^^^^if guess>number:
^^^^^^^^print("guess big")
^^^^ elif guess<number:
^^^^^^^^print("guess too small")
^^^^ elif guess==number:
^^^^^^^^print("You won")
^^^^^^^^break
^^^^ count=count + 1
^^^^if count>10:
^^^^^^^^print("You lost")
^^^^^^^^break
  • Did not guess right, guessed 3 times higher, guessed lower 4 times
  • Guess right Yes, 2 guesses too big, 3 times too small
  • No guess Yes, guessed big 5 times, guessed small 2 times
  • Guess right Yes, guess big once, guess small once

24. There is the following program segment, where x =3 when k takes the value of ( ). [picture is missing]

  • 3 4 5
  • 1 2
  • 5 6 7
  • 5 6

25. The code for finding an even number smaller than 10 and greater than or equal to 0 is as follows, please complete the code. x = 10 while x: x = x-1 if x%2!=0: ( ) print (x)

  • break
  • continue
  • yield
  • flag

26. Define the class as follows, the following code can be executed normally ( ).

class Show:
^^^^def __init__(self,name):
^^^^^^^^self.name=name
^^^^def showInfo(self):
^^^^^^^^print(self.name)
  • h = Show h.showInfo ()
  • h = Show() h.showInfo(“Zhang San”)
  • h = Show(“Zhang San”) h.showInfo()
  • h = Show(‘admin’) showInfo

27. After the following statement is executed, the ( ) line “I love python” will be output
i=10
while i>=0:
^^^^print(“I love python”)
^^^^ i=i-1

  • 1
  • 10
  • 11
  • 12

28. To find an even number smaller than 10 and greater than or equal to 0, the blanks in the following programs should be filled with ()
x = 10
while x:
^^^^x = x-1
^^^^if x%2!=0:
^^^^ ________
^^^^print (x)

  • break
  • continue
  • pass
  • False

29. Which of the following is wrong about the control structure of Python ( )

  • after each if condition Use a colon (:)
  • in Python In, there is no switch-case statement
  • in Python The pass is an empty statement, generally used as a placeholder statement
  • elif can be used alone

30. Execute the following code, and the result is ( ).

  • 0
  • 45
  • 55
  • 66

1. Compare the lengths of two strings (use newline to distinguish), and output the string with the longer length. If both strings have the same length, output the 1st string. Python3
Input: two strings
output: long string

a=input()
b=input()
if(len(a)>=len(b)):
    print(a)
else:
    print(b)

2. Give a 100-point grade, and require output grades ‘A’, ‘B’, ‘C’, ‘D’, ‘E’. Python3
90 points or more
A 80-89 points are B 70-79 points are C 60-69 points are D Below 60 points are E
Input: an integer within 0-100
Output: One character representing grade level

num=input()
num=int(num)
if num >= 90:
    print("A")
elif num >= 80:
    print("B")
elif num >= 70:
    print("C")
elif num >= 60:
    print("D")
else:
    print("E")

3. Award-winning Python3
topic description
In a certain competition, the judging rule is to sort from the most to the least according to the number of solved problems. If the number of solved problems is the same, the total scores (guaranteed to be different) are sorted from high to low, and the top 60% are selected. The participating teams (rounded to the nearest whole number) win the prize, please determine whether a certain team can win the prize.

Input format:
First enter a positive integer T, which represents the number of groups of test data, and then T groups of test data. Enter an integer n (1≤n≤15) and a string ms (length less than 10 and without spaces) in the first line of each test, which respectively represent the total number of participating teams and a certain team that wants to determine whether they can win the prize name; in the next n lines, enter the problem-solving information of n teams, each line contains a string s (length less than 10 and does not contain spaces) and two integers m, g (0≤m≤10, 0≤g ≤100), which respectively represent the team name, the number of problems solved, and the score of a team. Of course, n team names must contain ms.

Output format:
For each group of tests, if a certain team can win the prize, output “YES”, otherwise output “NO”. Quotes do not have to be output.

Input sample:
1
3 team001
team001 2 27
team002 2 28
team003 0 7
Sample output:
YES

def Win(list,name):
    list.sort(key=lambda x:(-x[1],-x[2]), reverse=True)
    index=-1
    for i in range(len(list)):
        if name==list[i][0]:
            index=i
    if index < len(list)*0.6:
        print("YES")
    else:
        print("NO")


n = int(input())
for _ in range(n):
    m,name=input().split(" ")
    m=int(m)
    list=[]
    for _ in range(m):
        name1,num1,score1=input().split(" ")
        list.append((name1,int(num1),int(score1)))

    Win(list,name)

1. Find the value of Sn=a + aa + aaa + … + aa…aaa (there are n a’s), where a is a number. In this question, a=2. For example: 2 + 22 + 222 + 2222 + 22222 (n=5), n is input by the keyboard. Python3
If n=4, then the sum is 2 + 22 + 222 + 2222 = 2468.

def fuck(num, n):
    # print(n)
    sum=num
    key=num

    i = 0
    while i < n:
        sum=sum*10 + key
        i + =1
    return sum


a=2
n=input()
mmm=int(n)
sum1=0
i=0
while i<mmm:


    sum1 + =fuck(a,i)
    i + =1
print(sum1)