Python2021 March Python Level 2--Analysis of Programming Questions

Topic 1
: Design a parking lot charging calculator (charging rules, charge 5 yuan within 2 hours, and add 2 yuan per hour for excess), the requirements are as follows:
1. The designed program must be able to input parking time (unit is hour, input The number of hours is an integer
2. The program can automatically calculate the parking fee based on the entered parking time and display it;
3. The program can be used repeatedly

Answer:

while True:
    a=int(input())
    c=5
    if a<=2:
        print("停车时间小于2小时","收费%d元"%c)
    else:
        c=c+2*(a-2)
        print("停车时间%d小时"%a,"收费%d元"%c)

Question 2:
The user inputs a radius r, and finds the area s and circumference C of the circle under this radius. The requirements are as follows
(1) Both the output area and perimeter should retain two decimal places: (2) The output format is: "The circumference of the circle is ** and the area is **" (3)
Pi is 3.14;
(4) Use print() formatted output (% method).
Answer:

r=float(input())
pi=3.14
s=2*pi*r**2
c=2*pi*r
print("圆的周长是%0.2f"%c,"面积是%0.2f"%s)

If you feel that you have gained something, you are welcome to give me a reward———— to encourage me to output more high-quality content

Insert image description here

Guess you like

Origin blog.csdn.net/weixin_40762926/article/details/132597747