0

I am trying to write a function that checks whether or not variables a and s are of type int or float, if not it prints the print statement below. The if function does not work however how would I be able to fix it?

a = 2
s= "hello"
if ((type(a) not (float or int)) and (type(s) not (float or int))):
    print(f'Invalid a type:{type(a)} s type: {type(s)}\Make sure to use float or int as for a and s values
python_user
  • 5,375
  • 2
  • 13
  • 32
tony selcuk
  • 709
  • 3
  • 11
  • `not isinstance(a, (float, int))`…! https://docs.python.org/3/library/functions.html#isinstance – deceze May 01 '21 at 06:20
  • Also `if ((type(a) not in (float, int)) and (type(s) not in (float, int)))` should be able to fix your original approach – mangupt May 01 '21 at 06:24

0 Answers0