I have TypeError: a float is required when I try putting type() with if statement
example:
from math import *
x=input("Enter a Number: ")
if type (sqrt(x)) == int:
print (sqrt(x))
else:
print("There is no integer square root")
obviously I can't use x= float(x)
解决方案
there are 2 problems here :
1st
x=input("Enter a Number: ")
will be a string, not a number, using int(x) should fix this
2nd
if type (sqrt(x)) == int:
sqrt() always return a float, you can use float.is_integer(), like this : sqrt(x)).is_integer() to check if the square root is a integer.
final code :
from math import *
x=int(input("Enter a Number: "))
if sqrt(x).is_integer():
print (sqrt(x))
else:
print("There is no integer square root")