if statement - Creating a function in Python that gets divided until it is in a certain range -
if statement - Creating a function in Python that gets divided until it is in a certain range -
i trying create function take input , split until within range.
let's input "2600" , want seek , split until within 500 , 1000 , homecoming number. this
try 2600 / 1 , see it's not in range , seek again
then 2600 /2 , see it's not in range , seek again
then 2600 /3 , see it's in range , homecoming 866
anyway, i'm doing in python 2 , think thinking in right direction, syntax tripping me up.
def octavesort(input,counter1): if input > (frequency * 2): test = input / counter1 if test > (frequency * 2): octavesort(input,counter1+1) else: homecoming test else: homecoming test
do really want split input number every positive integer until it's in range? name of function, suspect want split powers of 2, bring frequency desired octave. anyway, i've written both versions. :)
#! /usr/bin/env python def octavesort0(num, lo, hi): = 2.0 x = num while not lo <= x <= hi: x = num / #print i, x += 1.0 homecoming x def octavesort1(num, lo, hi): = 2.0 x = num while not lo <= x <= hi: x = num / #print i, x *= 2.0 homecoming x octavesort = octavesort1 def main(): lo, hi = 500, 1000 print octavesort(23456, lo, hi) if __name__ == '__main__': main() btw, shouldn't utilize input variable name because it's name of built-in function.
python if-statement
Comments
Post a Comment