I am getting an error in Codercise S.3.2,

Error: name ‘Fraction’ is not defined.

Can someone tell me how i can resolve this

I am getting an error in Codercise S.3.2,

Error: name ‘Fraction’ is not defined.

Can someone tell me how i can resolve this

Hi @Mukul,

~~This means that you’re using a variable called “Fraction” but you haven’t defined it earlier in your code. I hope this helps you resolve the issue ~~

Edit: see answer below

About this exercise:

“Assuming that we have the `get_phase`

function, obtain the value of the period with the procedure explained above. Help yourself to the function `Fraction`

(it is already imported for you).”

It seems it’s not imported, or am I wrong?

Tnx

You’re totally right.

I’m sorry for my previous answer @Mukul, I didn’t realize you were referring to the import.

You can use `fractions.Fraction`

. I’ve tested it and it works. I’m also updating the text in the Codercise so that it’s no longer confusing. Thanks for pointing this out.

Hi! Thank you for your answer, It keeps saying “Error: name ‘Fraction’ is not defined.”

piece of code :

" fraction = Fraction(phase).limit_denominator(2 ** n_estimation_wires)

denominators.append(fraction.denominator)"

Ok, solved.

But even if I got the proper output, it says Error: Your function does not return the expected value.

Output : 4

Nevermind! Solved. Sorry for the spam

Hi @CoxFox, no problem!

We’ve updated the text in the Codercise to reflect that you should use `fractions.Fraction`

instead of just `Fraction`

. Thanks for helping us improve! This will probably avoid confusions for many others in the future

1 Like

I’ve completed the whole Shor’s Algorithm series, it’s been very funny!!

Thanks for your precious support!

That’s great to hear @CoxFox ! Congratulations!