我在这个方程上遇到了麻烦。
from __future__ import division
import math
pi = 3.14159265
g = 6.67428*(10**-11)
user_circum = raw_input("Circumference (km) of planet? ")
user_acc = raw_input("Acceleration due to gravity (m/s^2)?")
def display_results(radius , mass , velocity):
print "Radius of the planet" , radius ,"km"
print "Mass of the planet" , float(mass/10**15) ,"(10^21 kg)"
print "Escape velocity of the planet" , velocity/1000 , "(km/s)"
def escape_velocity(circumference , acceleration):
circumference = float(circumference)
acceleration = float(acceleration)
radius = circumference/(2*pi)
mass = (acceleration * radius ** 2)/g
vEscape = ((2*g*mass)/radius) ** 0.5
display_results(radius , mass , vEscape)
escape_velocity(user_circum, user_acc)
使用 38000 和 9.8 的用户输入:
Circumference (km) of planet? 38000
Acceleration due to gravity (m/s^2)? 9.8
我应该得到这个答案:
Calculating the escape velocity...
Planet radius = 6047.9 km
Planet mass = 5370.7 x 10^21 kg
Escape velocity = 10.9 km/s
但相反,我得到了逃逸速度的答案。前2个是正确的。
Escape velocity of the planet 0.344294353352 (km/s)
这是逃逸速度的公式 √2gm/r 知道如何解决这个问题吗?太感谢了。我怎么能把我的答案四舍五入到小数点后一位?谢谢。