嘿,伙计们,我要做的是做一个非常基本的运动学变量解算器,所以我得到了基本方程vf=vi+at。现在我要做的是,如果你不知道这个变量,你输入/哪个是你要解的变量。但问题是,当我尝试输入变量as/时,它会给我一个错误,因为我使用的是整数。但是如果我从每个变量中去掉int(),它就不会让方程起作用!我被卡住了,如果有人能给我一些建议,我将不胜感激。好像我的图片没有上传,所以这里有一个gyazo链接https://gyazo.com/3325b42c51f839dc901cdefc1fe9b7fd
vf = input("What is the final velocity?")
if vf == "/":
dontuse = "vf"
else:
pass
vi = int(input("What is the intial velocity?"))
if vi == "/":
dontuse = "vi"
else:
pass
a = int(input("What is the acceleration?"))
if a == "/":
dontuse = "a"
else:
pass
t = int(input("What is the time?"))
if t == "/":
dontuse = "t"
else:
pass
def eq1():
vf = vi + a*t
def eq2():
vi = vf/(a*t)
def eq3():
t = (vf - vi)/a
if dontuse == "vf":
eq1()
好的,问题是你以Int的形式输入,但是你要求用户输入“/”,这是一个字符串。 在某些版本中,这不会给出错误,但在这里会给出错误
第二,你在计算Int变量,这是无效的乘法和除法,所以我用浮点,这是更好的准确性。你知道吗
享受:)
相关问题 更多 >
编程相关推荐