Luogu question solving Python language | P2433 Primary school mathematics N in one

Learn Python from a young age! Record the questions in the Luogu Python learning and exam preparation process, and record every moment.

Attached is a summary post: Luogu’s Python language | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

Question 1

Please output I love Luogu!

Question 2

There are 10 apples here, Little A took 2, Uim took 4, and Yao Yao took all the remaining apples. we want to know:

  1. How many apples did Little A and Uim take in total?
  2. How many apples can Yatsuo Isamu take away?

Now you need to write a program that outputs two numbers as the answer, separated by spaces.

Question 3

There are 14 apples now. Divide the apples equally among 4 students and put the remaining apples back in the refrigerator. Excuse me:

  1. How many apples can each student get?
  2. How many apples were distributed in total?
  3. Put a few apples back in the refrigerator?

Now you need to write a program that outputs three numbers as the answer, one line for each number.

Question 4

Now there are 500 ml of Feizhai Happy Water. It needs to be divided equally among 3 students. How many ml can each student get? Please output a number as output. Keep 6 significant digits and do not use scientific notation.

Question 5

Train A is 260 meters long and travels 12 meters per second; train B is 220 meters long and travels 20 meters per second. The two trains are moving towards each other. The timing starts when the two trains meet at the front. How long will it take for the two trains to meet at the rear? Leave? The answer is known to be an integer.

Question 6

The length and width of a rectangle are 6 cm and 9 cm respectively. Find its diagonal length (cm). Use cout output directly.

Question 7

There is 100 yuan in Uim's bank account. After the following operations:

  1. Deposited 10 yuan into it;
  2. Spent 20 yuan on shopping;
  3. Take out all the money inside.

Please output the account balance after each operation and separate it with line breaks.

Question 8

When the radius is  r =5, please output the circumference, area and volume of the circle. Take  π =3.141593. Please use cout directly to output the answer, one number per line.

Question 9

A little monkey bought some peaches. On the first day, he ate half of these peaches, and greedily ate one more; on the second day, he also ate half of the remaining peaches, and greedily ate one more; He dropped half of the peach and greedily ate one more. When I got up on the fourth day, I found that there was only one peach left. How many peaches did the little monkey buy?

Question 10

Luogu's evaluation tasks increase evenly per unit time. 8 evaluation machines can just finish evaluating the programs in the evaluation queue in 30 minutes, and 10 evaluation machines can just finish evaluating the programs in the evaluation queue in 6 minutes. How many evaluation machines can just finish evaluating the programs in the evaluation queue in 10 minutes? Program evaluation completed?

Question 11

Little A runs at a speed of 5 m/s, and Isamu Yao runs at a speed of 8 m/s. Isao is 100 meters behind Little A. They start running at the same time. How long will it take for Isamu to catch up with Little A? Output a number to represent the answer, use cout to output directly.

Question 12

Everyone knows that there are 26 English letters, of which A is the first letter. Now please program to find out:

  1. What letter of the alphabet is M?
  2. What is the 18th letter?

Output a number and a letter, separated by a newline.

Question 13

Little A has two spherical pieces of plasticine, one with a radius of 4 and the other with a radius of 10. He wants to knead these two pieces of plasticine together and then shape them into a cube. What is the edge length of this cube? If the result is not an integer, digits after the decimal point are rounded off. Take  π =3.141593.

Question 14

According to Gugu Online School's prediction, when the course is priced at 110 yuan, 10 people will sign up. If the course price decreases by 1 yuan, there will be 1 more registrants (and vice versa). If you want to receive a total of 3,500 yuan in tuition fees, how much should you price it? Given that there are two answers to this question that meet the requirements, choose the smaller one. If the answer is not a whole number, round to the nearest whole number.

【enter】

Enter a positive integer indicating the question number.

【Output】

According to the entered question number, the answer to the corresponding question is output.

【Input sample】

2

【Output sample】

6 4

[Detailed code explanation]

import math
num = int(input())
if num == 1:
    print("I love Luogu!")
elif num == 2:
    print(2+4, 10-2-4)
elif num == 3:
    print(14//4)
    print(14//4*4)
    print(14 - 14//4*4)
elif num == 4:
    print(500/3)
elif num == 5:
    print((260+220)//(12+20))
elif num == 6:
    print("%.4f" % math.sqrt(6**2+9**2))  
elif num == 7:
    print(100+10)
    print(100+10-20)
    print(0)
elif num == 8:
    print("%.4f" % (2*3.141593*5))  
    print("%.4f" % (3.141593* (5**2)))  
    print("%.3f" % (4/3 * 3.141593 * 5**3))  
elif num == 9:
    print(22)
elif num == 10:
    print(9)
elif num == 11:
    print("%.4f" % (100/(8-5)))
elif num == 12:
    print(ord('M') - ord('A') + 1)
    print(chr(ord('A')+18-1))
elif num == 13:
    print(int(math.pow((4 / 3 * 3.141593 * 4 ** 3 + 4 / 3 * 3.141593 * 10 ** 3), 1 / 3)))
elif num == 14:
    print(50)

【operation result】

2
6 4

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132775628
Recommended