-1

我是 JES 的新手,我坚持这一点,我确定我的编码是错误的。如果我输入我的年龄为 21,我希望将 2 分配给变量 a,将 1 分配给变量 b。

非常感激任何的帮助。

  def makeSound():
    picture=makeEmptySound(10 * 22050)
    number = requestNumber("Enter Your Age:") 
    a = String('number[1]')
    b = String('number[2]')
    setMediaPath("c:\")
    file = getMediaPath(str(a) + str(b) + ".wav")
4

1 回答 1

3

在 Python 中,序列类型str的索引从零开始,因此假设requestNumber()返回 a float,您需要将其转换为 a str,然后您可以执行以下操作:

number = requestNumber("Enter Your Age:") 
number_as_string = str(number)
a, b = number_as_string[0], number_as_string[1]
# [...]
file = getMediaPath(a + b + '.wav')
于 2013-12-17T08:49:35.727 回答