Converting input containing special character to float
For reading a fraction such as "97/100", you can use the fractions library.

For example:



from fractions import Fraction

f = Fraction("97/100")

print(float(f)) # prints 0.97


And because the constructor also takes a float, we can remove the check for /. Therefore, the final code is:

from fractions import Fraction

def toNum(interest):
    f = Fraction(interest)
    f = float(f)

    if f &gt; 1:
        f /= 100

    return f

print(toNum("97/100")) # prints 0.97
print(toNum(0.97)) # prints 0.97
print(toNum(9)) # prints 0.09