import rex = "h01234"match = re.search("\D", x)if not match:print("x is a number")else:print("encountered a problem at character:", match.group(0))
Result: "encountered a problem at character: h"
intchecker = float(input('Please enter a integer: '))intcheck = 0while intcheck != 1:if intchecker - int(intchecker) > 0:intchecker = float(input("You didn't enter a integer. ""Please enter a integer: "))else:intcheck = 1print('you have entered a integer')
import mathprint ("this program will tell you if a number is square")print ("enter an integer")num = float(input())if num > 0:print ("ok!")num = (math.sqrt(num))inter = int(num)if num == inter:print ("It's a square number, and its root is")print (num)else:print ("It's not a square number, but its root is")print (num)else:print ("That's not a positive number!")
def isInt(anyNumberOrString):try:int(anyNumberOrString) #to check float and int use "float(anyNumberOrString)"return Trueexcept ValueError :return False
isInt("A") #FalseisInt("5") #TrueisInt(8) #TrueisInt("5.88") #False *see comment above on how to make this True