I'm trying to implement the try...except
exception handling into the code below. When something like "s4" is entered, I want the output of "Non numeral value..." to appear.
Any idea on where I've gone wrong?
import string
import math
def getSqrt(n):
return math.sqrt(float(n))
s = input("Enter a numerical value: ")
try:
for i in s:
if (i.isdigit() or i == "."):
sType = "nonstr"
if (sType =="nonstr"):
print(getSqrt(s))
else:
s = "Non numberical value..."
except ValueError as ex:
print(ex)
else:
print(s)