Name not defined, but if I have defined it

-1

I have this code, but when compiling it tells me that guess is not defined, when it's a couple of lines up. I've tried everything, I put the original code (it's not mine) because I do not know what I've done:

from fractions import Fraction
def sampled_freq_to_period(sampled_freq, num_freqs, max_period):
f = Fraction(sampled_freq, num_freqs)
r = f.limit_denominator(max_period)
return r.denominator
guess = sampled_freq_to_period(sampled_freq=171,
                           num_freqs=1024,
                           max_period=21)
print(guess)
    
asked by neok 08.12.2018 в 20:46
source

1 answer

0

I think the error is that you did not decode the function, so when you declare the variable 'guees' it recognizes it as if it were inside a function which is not read until it is called in any case it would be something like that

from fractions import Fraction
def sampled_freq_to_period(sampled_freq, num_freqs, max_period):
    f = Fraction(sampled_freq, num_freqs)
    r = f.limit_denominator(max_period)
    return r.denominator

guess = sampled_freq_to_period(sampled_freq=171,
                           num_freqs=1024,
                           max_period=21)
print(guess)
    introducir el código aquí
    
answered by 14.12.2018 в 23:13