编码练习:观察钟摆



在物理学中,对于长度为 L 且初始角为 A 的摆锤,它在时间 T 处的水平>位移 X(T) 由公式给出 X(T) = L × cos(A × cos(T × √9.8/L)) - L × cos(A)

编写一个需要两行输入的程序;第一行是L,第二行是>A。输出应该是十行,给出 X(0)、>X(1)、X(2)、...、X(9) 的值。例如,如果输入的第一行是 53.1,>第二行输入是 0.8,则第一行输出为 0.0,第二行>输出为 53.1*cos(0.8*cos(1*√9.8/53.1)) - 53.1*cos(0.8) ~ 2.6689。

import math 
L = float(input())
A = float(input())
for T in range (0,9):
print(L*math.cos(A*math.cos(T*math.sqrt(9.8/L))-L*math.cos(A)))

我已经写了这篇文章,我不明白我做错了什么?

输入:

53.1
0.8

我的输出:

3.545012155898153
7.383727226708044
17.92714440725987
31.889478979714276
44.23118522394127
51.212404291669216
53.079364553814806
52.890770379027806
52.999922313121566

预期答案:

0.0
2.6689070487226805
9.021742145820763
14.794542557581206
15.73774678328343
11.124903835610114
4.423693604072537
0.27377375601245213
1.295906539090336
6.863309996333497

你在错误的地方有一个括号,改变

L*math.cos(A*math.cos(T*math.sqrt(9.8/L))-L*math.cos(A))

L*math.cos(A*math.cos(T*math.sqrt(9.8/L)))-L*math.cos(A)

这在我的电脑上给出了正确的输出

编辑: 同时将range(0,9)更改为range(10)

最新更新