Search Results

Search found 1 results on 1 pages for 'user1432941'.

Page 1/1 | 1 

  • The return value should be a list but doesn't return as expected?! - Python newbie

    - by user1432941
    Hi this must be a very simple solution that has eluded me this last hour. I've tried to build this test function where the return value of the test_cases list should match the values in the test_case_answers list but for some reason, test case 1 and test case 2 fail. When i print the return values for the test cases they return the correct answers, but for some reason test case 1 and test case 2 return False. Thanks for your help! import math test_cases = [1, 9, -3] test_case_answers = [1, 3, 0] def custom_sqrt(num): for i in range(len(test_cases)): if test_cases[i] >= 0: return math.sqrt(test_cases[i]) else: return 0 for i in range(len(test_cases)): if custom_sqrt(test_cases[i]) != test_case_answers[i]: print "Test Case #", i, "failed!" custom_sqrt(test_cases)

    Read the article

1