Question

I'm new to JES and I'm stuck on this, I'm sure my coding is wrong. If I entered my age as 21 I want the 2 allocated to variable a and 1 allocated to variable b.

Any help would be most appreciated.

  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")
Was it helpful?

Solution

Indexes into sequence-types like str are zero-based in Python, so assuming requestNumber() returns a float, you'll need to convert it to a str and then you can do:

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')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top