Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:03:28+00:00 2026-06-05T13:03:28+00:00

This must be a very simple solution that has eluded me this last hour.

  • 0

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.

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:03:41+00:00Added an answer on June 5, 2026 at 1:03 pm

    You are looping too many times. In custom_sqrt, you try to loop over all test cases, but you return the value for the first one, so you never get to the rest. Remove your loop from custom_sqrt so it’s just:

    def custom_sqrt(num):
        if num >= 0:
            return math.sqrt(num)
        else: 
            return 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be very simple, but I couldn't find it on the documentation. In
I must be missing something very simple, but can't find the answer to this.
This must be very trivial, but I can't find it out: struct Test {
There must be a simple solution to this problem but for the love of
This must be a very stupid question, but how does one recode with Xuggler?
The idea it's very easy, i have an http download class, this class must
There must be a very easy way to do this but I don't know
This seems very basic and I must be missing something, but here goes anyways...
This must be a simple question, but as an R newcomer I haven't been
I must be overlooking something very simple here but I can't seem to figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.