Python classroom exercise 2

Written above, these questions are for me to learn Python and practice. The answers are for reference only.

Sub topic 1:

[Title Description] the teacher released the online classroom exercise and stipulated that the five students who completed the submission first can be rewarded. There is a group of student numbers arranged according to the submission time sequence (the numbers may be repeated), and it is required to count the number of 5 students who can win the prize. If it is less than 5 bits, it will be output according to the actual quantity.

[enter description] line, containing a group of positive integers separated by spaces, representing the student number.

[output description] one line, output 5 non duplicate numbers in the original order, separated by spaces. If it is less than 5, it shall be output according to the actual quantity.

[input example] 10   fourteen   ten   twenty-three   nine   twenty-three   ten   thirty   twenty-seven   thirteen

[output example] 10   fourteen   twenty-three   nine   30 Good job!

a = list(map(str,input().split())) #Enter student number
b = [] #List of outputs
for c in a:
    if c not in b: #Judge whether the extracted value exists
        b.append(c)#Add this value to b
for d in b[0:5]:#Top 5
    print(d,end ='\t' )
print("Good job!")

Sub topic 2:

[Title Description] there are three members in each of the two groups A and B. each person draws a number card (1 ~ 9). Find the product of the numbers on the three number cards of the two groups.

[enter description] contains two lines with 3 integers each. Represents three numbers drawn from each of the two groups.

[output description] contains one line and two integers, which are the product of three numbers in each group.

[input sample]

1 2 3

2 3 4

[output sample]

6  24

a,b,c = map(int,input().split())
d,e,f = map(int,input().split())
g = a*b*c
f = d*e*f
print(g,f)

Sub topic 3:

[Title Description] there are m soldiers who have lined up and numbered 1~m in order. Now they need to queue up again. The queuing rules are: start from Soldier 1, skip one, and then line up one more until the round is completed, and then list them in order again among the remaining soldiers

The first column, one at an interval, and then one out of the column, and continue the cycle until all the columns are out of the column. Please output the soil soldier number in the order of listing.

[enter description] a positive integer indicating the number of soldiers.

[output description] the numbering sequence of soldiers, separated by spaces.

[input example] 10

[output example] 1 3 5 7 9 2 6 10 4 8

a = int(input())#To what
ls1 = []
ls2 = []
for b in range(1,(a+1)): Remove all values
    ls1.append(b)#Put values in list 1
while len(ls1) != 0:#Determine whether list 1 still has a value
    for b in ls1[::2]:#0:: 2 fetches the value of odd digits in the list
        ls2.append(b)#Put the extracted value into list 2
    del(ls1[::2])#Delete the extracted value
for c in ls2:#Take out the value in list 2
    print(c,end="\t")

Sub topic 4:

[Title Description] input the height of all students in a class and output the height of those students who exceed the average height. The input of the program is a line of data separated by spaces, and each data is a positive integer.

[enter description] line, including several positive integers, indicating the height of the whole class.

[output description] output an integer indicating the number of students above the average height.

[input example] 143   one hundred and seventy-four   one hundred and nineteen   one hundred and twenty-seven   one hundred and seventeen   one hundred and sixty-four   one hundred and ten   one hundred and twenty-eight

[output example] 3

a = list(map(str,input().split())) #Enter height
b = len(a)#How many values are there in total
c = 0
sum = 0
for d in a:
    c = c+int(d)#Add all heights
    e = c/b #Average height
for f in a:
    if int(f) > e:#Judge whether it is greater than the average height
        sum += 1#accumulation
print(sum)

Sub topic 5:

Many families take their children out to travel during the summer vacation. The admission fee standard of a tourist attraction is: those less than 1.2m in height are free of admission; Half ticket for those who are 1.2m and above, and full ticket for those who are 1.5m and above

Now enter the full ticket price of the scenic spot and the height of each person of a tourist group. Please calculate the total ticket cost of the tourist group in the scenic spot.

[enter description] two lines. The first behavior is the price of all tickets. The second line is several decimals (separated by spaces), indicating the height of each person in the tour group.

[output description] a decimal, indicating the total ticket cost of the tour group in the scenic spot. Accurate to one decimal place.

[input sample]

100

1.0  0.8  1.2  1.3  1.4  1.5  1.6  1.7

[output sample]

450.0

a = int(input())#Ticket Price
b = list(map(float,input().split())) #Everyone's height
sum = 0#Total price
for c in b:
    if c >= 1.5:
        sum=sum+a
    elif c>1.2 and c<1.5:
        sum=sum+(a/2)
print(sum)

Sub question 6:

[Title Description] now it is necessary to calculate the score of the experimental class group. The calculation rule is: after removing one highest score and one lowest score, calculate the average score (keep 2 decimal places) as the group score, and output it according to the format requirements.

[enter description] line, the scores of each member of the group, separated by spaces (more than 2 members of each group)

[output description] group score.

[input example] 97   ninety-eight   ninety-nine

[output example] 98.00

a = list(map(str,input().split()))#Group score
min = min(a)
max = max(a)
a.remove(min)
a.remove(max)
count=len(a)#Number of remaining
c = 0
for b in a:
    c = c+float(b) #The sum of the remaining numbers
    d = c/count#Average
    d = round(d,2)#Keep two decimal places
print(d)

Sub question 7:

[Title Description] in order to improve delivery efficiency, towels in the warehouse have been packed in one package according to n articles. If the order quantity is just an integral multiple of N, it can be shipped directly in the original packaging. There are 5 orders. According to the order quantity of each order, it is judged that several orders can be delivered directly in the original packaging.

[input description] two lines. The first line contains 1 integer, indicating the number of items in each package, and the second line contains 5 positive integers, respectively indicating the order quantity of each order.

[output description] line, including 1 integer, indicating the number of orders that can be shipped directly in the original packaging.

[input sample]

30

20  30  40  50  60

[output sample]

2

a = int(input())
b =list(map(str,input().split()))
sum = 0
for c in b:
    if int(c) % a ==0:
        sum+=1
print(sum)

Sub topic 8:

[Title Description] enter an English article containing only English letters and spaces. According to the order of occurrence, output the words in the article one by one, and output the words that appear many times only once. Words are not case sensitive and are output in lowercase.

[enter description] 1 line indicates an English article, which contains only English letters. Space.

[output description] 1 line, containing several words, separated by a space.

[input sample 1]

like Baby baby baby ohhh Baby baby Like nooo

[output example 1]

like baby ohhh nooo

a = list(map(str,input().split())) #Input article
b=[]
e=[]
for c in a:
    b.append(c.lower())#Change to lowercase
for d in b:
    if d not in e:
        e.append(d)
for f in e:
    print(f,end=" ")

Sub question 9:

Program functions:

Enter any month and output the name of the season. For example, March May is spring, June August is summer, September November is autumn, and December February is winter.

[enter description]

An integer representing the month.

[output description]

Name of output season: spring, summer, autumn and winter.

[input sample] 5

[output example] spring

a = int(input())
if a == 3 or a == 4 or a == 5:
    print("spring")
if a == 6 or a == 7 or a == 8:
    print("summer")
if a == 9 or a == 10 or a == 11:
    print("autumn")
if a == 12 or a == 1 or a == 2:
    print("winter")

Keywords: Python Back-end

Added by rokkstar on Tue, 07 Dec 2021 21:27:48 +0200