在运行程序并提供用户输入时,它仅执行代码中的最后一个功能。我知道代码有什么问题,我用不同的参数重新定义了相同的函数。但是,我不知道如何更改它,以便代码将运行与用户输入匹配的功能。这是我为程序编写的代码。
this.mixer = new THREE.AnimationMixer(this.box);
this.animation = this.mixer.clipAction(this.box.geometry.animations[0]);
this.animation.setDuration(1.5);
this.animation.setLoop(THREE.LoopOnce, 1);
this.mixer.addEventListener( 'finished', function() {
this.animation.stop();
// HOW animation-fill-mode: forwards ?
});
答案 0 :(得分:1)
您需要给每个方程式函数一个唯一的名称。这将允许您构建一个将标识符映射到每个标识符的字典。另外,在调用所选函数之前,您需要获取一个参数值以传递所选函数。
这是做所有这些事情的一个例子:
import math
from math import pi
def equation1(Lift):
d = float(input("Input d value: "))
v = float(input("Input v value: "))
A = float(input("Input A value: "))
CL = float(input("Input CL value: "))
Lift = .5 * d * (v ** 2) * A * CL
a = ["Lift = ", Lift, "Newtons"]
for i in range (3):
print(a[i], end =" ")
def equation2(VCylinder):
r = float(input("Input r value: "))
h = float(input("Input h value: "))
VCylinder = pi * (r ** 2) * h
a = ["Volume of Cylinder =", VCylinder, "m³ (meters³)"]
for i in range(3):
print(a[i], end =" ")
def equation3(Exponentdx):
n = int(input("Input n value: "))
u = n
v = n - 1
a = ["dx =", u,"x","**", v, " "]
for i in range(5):
print(a[i], end =" ")
# Build dictionary mapping an equation identifer to equation functions.
equations = {
'1': equation1,
'2': equation2,
'3': equation3,
}
def Main():
print("Currently only compatible with base metric units (meters, kilograms, etc.)")
eq_id = input("Enter desired equation function (1, 2, or 3): ")
eq_arg = float(input("Enter value of argument to pass equation function: "))
equations[eq_id](eq_arg) # Call selected equation with argument.
Main()