编码调查,发现孔径大小

2024-09-25 08:30:18 发布

您现在位置:Python中文网/ 问答频道 /正文

实际上我不知道如何正确地提出这个问题,所以让我告诉你我的家庭作业是什么。。。你知道吗

“他们有直径从0.25米到8米的洞(挖隧道),大小增加了0.25米(0.25,0.5,0.75…7.75,8)。你知道吗

At a minimum, your application will:

-Ask the user for the minimum required volume of the tunnel

-Ask the user for the exact length of the tunnel

-Use a loop to determine the bore-size required as well as the exact volume that would be produced with that bore.

额外学分:

-Tell the user to extend the tunnel if the bore size required is greater than 8m.

-Allow the user to determine the volume of the tunnel with a given bore size and tunnel length

-Allow the user to determine the length of the tunnel with a given bore size and volume (in case the user would prefer to get an exact volume but is flexible with the tunnel length.)

-Provide the user with a list of alternatively shaped prisms (and their dimensions) that could fit the volume and length requirements."

我试过这个,但看起来不对

from math import sqrt

a = float(input("What is the minimum volume that is required? (cubic metres): "))

b = float(input("How long do you need the tunnel to be? (metres): "))

pi = 3.14

r = sqrt(a/pi/b)

c = round(r, 2)

print(c)

对于a=250b=12的输入,当答案(假设)是2.75时,它提供了2.58的输出

我在想,你是怎么把2.58分调到2.75分的,如果你有时间的话,你对如何做额外的功能部分有什么想法/帮助/提示吗?你知道吗


Tags: andofthetosizethatiswith
1条回答
网友
1楼 · 发布于 2024-09-25 08:30:18

您可以使用循环来检查哪个元素高于某个值,并在达到该值后停止。一般来说,应该是这样的:

minimum_bore_size = 0.25
bore_size_step = 0.25
maximum_bore_size = 8

required_bore_size = math.sqrt(a / b / math.pi)

if required_bore_size > maximum_bore_size:
    print ('required bore size too big')
    # exit your program somehow

bore_size = minimum_bore_size
while bore_size < maximum_bore_size:
    if bore_size < required_bore_size:
        bore_size = bore_size + bore_size_step
    else:
        volume = math.pow(bore_size,2) * math.pi * b
        print(round(bore_size,2))
        print(volume)
        break

相关问题 更多 >