numerator, denominator = [float(s) for s in raw_input().strip().split("/")] print 2 ** (numerator/denominator)
I strip whitespace from the input, split it into parts, then convert the parts to numbers with a list comprehension.
This will fail if the input isn't in fractional form. To check and behave appropriately...
line = raw_input().strip() if "/" in line: numerator, denominator = [float(s) for s in line.split("/")] exponent = numerator/denominator else: exponent = float(line) print 2 ** exponent
If you had tried using 2 ** (1/2) and it had failed, that is because 1 and 2 are integers, so Python 2 uses integer division and ignores the fractional part. You could fix this by typing 1.0/2 into your script or input().