def isListOfSimpleNumeric(theList): """ indicates whether value of argument is a list of only simple numerics (int or float) Note: empty list should return True---it doesn't contain anything that ISN'T simple numeric theList can be anything, and it will return either True or False. >>> isListOfSimpleNumeric('Fred') False >>> isListOfSimpleNumeric(3) False >>> isListOfSimpleNumeric([3]) True >>> isListOfSimpleNumeric([3.4]) True >>> isListOfSimpleNumeric([2,3,4,5.6,7]) True >>> isListOfSimpleNumeric([2,3,'oops',5]) False >>> isListOfSimpleNumeric([2,3,[4]]) False >>> isListOfSimpleNumeric([]) True """ if not isList(theList): return False for item in theList: if not isSimpleNumeric(item): return False return True
def isListOfSimpleNumeric(theList): """ indicates whether value of argument is a list of only simple numerics (int or float) Note: empty list should return True---it doesn't contain anything that ISN'T simple numeric theList can be anything, and it will return either True or False. >>> isListOfSimpleNumeric('Fred') False >>> isListOfSimpleNumeric(3) False >>> isListOfSimpleNumeric([3]) True >>> isListOfSimpleNumeric([3.4]) True >>> isListOfSimpleNumeric([2,3,4,5.6,7]) True >>> isListOfSimpleNumeric([2,3,'oops',5]) False >>> isListOfSimpleNumeric([2,3,[4]]) False >>> isListOfSimpleNumeric([]) True """ if not isList(theList): return False for item in theList: if not isSimpleNumeric(item): return False return True
def isListOfSimpleNumeric(theList): # Returns True if "theList" is a list of only ints and floats, otherwise returns False if (not isList(theList)): return False # it isn't really a list! # Now we can assume that theList really is a list # But is it a list of all numerics? # If we find even a single item that isn't numeric, we can # immediately return false. for item in theList: if not isSimpleNumeric(item): return False # If we get here and didn't return yet, then we know everything # in the list is a simple numeric! # (i.e. there isn't anything in the list that is NOT simple numeric) return True
def isListOfSimpleNumeric(theList): """ indicates whether value of argument is a list of only simple numerics (int or float) Note: empty list should return True---it doesn't contain anything that ISN'T simple numeric theList can be anything, and it will return either True or False. >>> isListOfSimpleNumeric('Fred') False >>> isListOfSimpleNumeric(3) False >>> isListOfSimpleNumeric([3]) True >>> isListOfSimpleNumeric([3.4]) True >>> isListOfSimpleNumeric([2,3,4,5.6,7]) True >>> isListOfSimpleNumeric([2,3,'oops',5]) False >>> isListOfSimpleNumeric([2,3,[4]]) False >>> isListOfSimpleNumeric([]) True """ if (not isList(theList)): return False # it isn't really a list! # Now we can assume that theList really is a list # But is it a list of all numerics? # If we find even a single item that isn't numeric, we can # immediately return false. for item in theList: if not isSimpleNumeric(item): return False # If we get here and didn't return yet, then we know everything # in the list is a simple numeric! # (i.e. there isn't anything in the list that is NOT simple numeric) return True
def isListOfSimpleNumeric(theList): """ indicates whether value of argument is a list of only simple numerics (int or float) Note: empty list should return True---it doesn't contain anything that ISN'T simple numeric theList can be anything, and it will return either True or False. >>> isListOfSimpleNumeric('Fred') False >>> isListOfSimpleNumeric(3) False >>> isListOfSimpleNumeric([3]) True >>> isListOfSimpleNumeric([3.4]) True >>> isListOfSimpleNumeric([2,3,4,5.6,7]) True >>> isListOfSimpleNumeric([2,3,'oops',5]) False >>> isListOfSimpleNumeric([2,3,[4]]) False >>> isListOfSimpleNumeric([]) True """ if (not isList(theList)): return False # it isn't really a list! # Now we can assume that theList really is a list # But is it a list of all numerics? # If we find even a single item that isn't numeric, we can # immediately return false. for item in theList: if not isSimpleNumeric(item): return False # If we get here and didn't return yet, then we know everything # in the list is a simple numeric! # (i.e. there isn't anything in the list that is NOT simple numeric) return True
def test_isSimpleNumeric3(self): self.assertEqual(isSimpleNumeric("5"), False)
def test_isSimpleNumeric2(self): self.assertEqual(isSimpleNumeric(3.5), True)
def test_isSimpleNumeric3(): assert( isSimpleNumeric("5")== False)
def test_isSimpleNumeric2(): assert( isSimpleNumeric(3.5)== True)
def test_isSimpleNumeric1(): assert( isSimpleNumeric(5)== True)
def test_isSimpleNumeric2(self): self.assertEqual( isSimpleNumeric(3.5), True)
def test_isSimpleNumeric4(): assert( isSimpleNumeric([5])== False)
def test_isSimpleNumeric5(self): self.assertEqual( isSimpleNumeric(6.0221415E23), True)
def test_isSimpleNumeric4(self): self.assertEqual( isSimpleNumeric([5]), False)
def test_isSimpleNumeric3(self): self.assertEqual( isSimpleNumeric("5"), False)
def test_isSimpleNumeric4(self): self.assertEqual(isSimpleNumeric([5]), False)
def test_isSimpleNumeric5(self): self.assertEqual(isSimpleNumeric(6.0221415E23), True)
def test_isSimpleNumeric5(): assert( isSimpleNumeric(6.0221415E23)== True)