I’m attempting to write a simple python script that will calculate the squareroot of a number. heres the code i’ve come up with and it works. but i would like to learn how to use fractional exponents instead.
var1 = input('Please enter number:')
var1 = int(var1)
var2 = var1**(.5)
print(var2)
thanks for the help
You can use fractional exponents with the help of
fractionsmodule.In this module there is a class
Fractionwhich works similar to our inbuiltintclass.Here is a link to the documentation of the class – http://docs.python.org/library/fractions.html (just go through its first few examples to understand how it works. It is very simple.)
Heres the code that worked for me –