我有这个代码:请帮助我了解如何获取用户对方程式的输入。
from __future__ import division
pi = 3.14159265
g = 6.67428*(10**-11)
radius = raw_input("Enter Radius -->")
def display_results(radius , mass , velocity):
print "Radius of the planet" , radius/1000 ,"km"
print "Mass of the planet" , float(mass/10**21) ,"(10**21 kg)"
print "Escape velocity of the planet" , velocity/1000 , "(km/s)"
def escape_velocity(circumference , acceleration):
radius = circumference/(2*pi)
mass = (acceleration * radius ** 2)/g
vEscape = ((2*g*mass)/radius)**0.5
display_results(radius , mass , vEscape)
escape_velocity(40075000 , 10)
这是我应该做的:使用有效的主线逻辑来获取用户输入,然后调用 escape_velocity() 函数来计算并显示最终结果。下面是从您的程序运行的示例应该是什么样子(** ** 文本是来自用户的示例输入):
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
如何让用户输入一个数字,以便我的程序求解方程。我需要有用户输入:
Circumference (km) of planet?
Acceleration due to gravity (m/s^2)?
非常感谢!!